BackhardGraphs

Minimum Cycle Basis Enumeration Solution

Problem Statement

Given an undirected graph represented as an adjacency list, find a minimum cycle basis, which is a set of simple cycles with the minimum total length such that any other cycle in the graph can be expressed as a linear combination of these cycles.

Example 1
Input
Let the graph be represented as an adjacency list: {0: [1, 2], 1: [0, 2, 3], 2: [0, 1, 3], 3: [1, 2]}
Output
[[0, 1, 2, 0], [1, 2, 3, 1]]

Explanation: The minimum cycle basis consists of two cycles: 0-1-2-0 and 1-2-3-1.

Example 2
Input
Consider the graph represented as an adjacency list: {0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]}
Output
[[0, 1, 2, 3, 0]]

Explanation: The minimum cycle basis consists of a single cycle: 0-1-2-3-0.

Constraints

  • The graph is represented as an adjacency list.
  • The graph may contain self-loops and parallel edges.
  • The graph has at most 100 vertices and 500 edges.
  • All edge weights are assumed to be 1 for simplicity.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free