Minimum Cut (Stoer-Wagner) - Problem
Given an undirected weighted graph, find the minimum cut using the Stoer-Wagner algorithm. A minimum cut is the smallest sum of edge weights that, when removed, disconnects the graph into two components.
The graph is represented as an adjacency matrix where graph[i][j] represents the weight of the edge between vertices i and j. If there's no edge, the value is 0.
Return the weight of the minimum cut.
Input & Output
Example 1 — Simple Triangle Graph
$
Input:
graph = [[0,2,1],[2,0,1],[1,1,0]]
›
Output:
1
💡 Note:
The graph forms a triangle with edges: 0-1 (weight 2), 0-2 (weight 1), 1-2 (weight 1). The minimum cut is 1, achieved by removing edge 0-2 or edge 1-2, separating one vertex from the other two.
Example 2 — Linear Chain
$
Input:
graph = [[0,3,0,0],[3,0,2,0],[0,2,0,1],[0,0,1,0]]
›
Output:
1
💡 Note:
The graph forms a chain: 0-1-2-3 with weights 3,2,1. The minimum cut is 1 (edge 2-3), which separates vertex 3 from the rest of the graph.
Example 3 — Complete Graph
$
Input:
graph = [[0,1,1],[1,0,1],[1,1,0]]
›
Output:
2
💡 Note:
Complete graph with all edge weights 1. To disconnect any vertex requires cutting 2 edges, so minimum cut is 2.
Constraints
- 1 ≤ graph.length ≤ 15
- graph[i][j] = graph[j][i] (undirected graph)
- graph[i][i] = 0 (no self-loops)
- 0 ≤ graph[i][j] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code