最小割-poj-2914

简介: poj-2914-Minimum Cut Description Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must b

poj-2914-Minimum Cut

Description

Given an undirected graph, in which two vertices can be connected by multiple edges, what is the size of the minimum cut of the graph? i.e. how many edges must be removed at least to disconnect the graph into two subgraphs?

Input

Input contains multiple test cases. Each test case starts with two integers N and  M (2 ≤ ≤ 500, 0 ≤ ≤ × (N − 1) ⁄ 2) in one line, where N is the number of vertices. Following are M lines,  each line contains M integers A, B and C (0 ≤ A, B < N, A ≠ B, C > 0), meaning that there C edges connecting vertices A and B.

Output

There is only one line for each test case, which contains the size of the minimum cut of the graph.  If the graph is disconnected, print 0.

Sample Input

3 3

0 1 1

1 2 1

2 0 1

4 3

0 1 1

1 2 1

2 3 1

8 14

0 1 1

0 2 1

0 3 1

1 2 1

1 3 1

2 3 1

4 5 1

4 6 1

4 7 1

5 6 1

5 7 1

6 7 1

4 0 1

7 3 1

Sample Output

2

1

2

微笑题目大意:有重边的无向图,至少删去多少条边能使其变为非连通图?

分析:传统最小割最大流算法需要枚举汇点,复杂度为O(n^4)以上,故有时会超时。本题用Stoer-Wagner 算法。

微笑Stoer-Wagner 算法用来求无向图 G=(V, E)的最小割。

算法基于这样一个原理:定义图G的最小割为MinCut,对于任意顶点s,t VMinCut=min(s-t最小割,将sv缩点之后的MinCut)。在此不予证明。

Stoer-Wagner 算法流程:

1. 初始置最小割MinCut INT_MAX

2. 在 G中求出任意 s-t 最小割 c,更新MinCut = min(MinCut, c) 

3. 对 G中的顶点s,t做缩点操作。若G中顶点已被缩为一个,当前MinCut即为所求。 

----缩点操作:

ab进行缩点: 删掉点 a, b 及边(a, b),加入新节点 c,对于任意 vmat(c,v) = mat(v,c) = mat(a, v) + mat(b,v)  

---求 G=(V, E)中任意 s-t 最小割的算法:

为点集,x不属于A,定义dist[x] = mat(v[i], x)v[i]

1. 初始令集合 A={a}a为 V中任意点 。

2. 选取 V - A中的 dis[ x ]最大的点 x加入集合 

3.更新V-A中顶点的dist[ ]

4.|A|=|V|,结束。令倒数第二个加入 A的点为 s,最后一个加入 A的点为 t,则s-t 最小割为dist[t]

微笑


 

目录
相关文章
|
存储
|
人工智能 机器学习/深度学习
|
人工智能 算法 BI
poj 2192 Zipper
题目链接:http://poj.org/problem?id=2192 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18658   Accepted: 6651 Description Given ...
951 0
POJ 2262 Goldbach&#39;s Conjecture
Problem Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the foll...
968 0
|
机器学习/深度学习
|
SDN
poj 2886 Who Gets the Most Candies?
点击打开poj 2886 思路: 求因子数+单点更新 分析: 1 题目的意思是有n个人构成一个环,刚开始是第k个人先出来。每个人有一个名字和数值A,如果A为正数,那么下一个出去的人是他左边的第A个人,如果是负数那么出去的将是右边的第A个人 2 这么我们要注意一下,因为n个人是围城一圈,那么左边就是顺时针方向,右边就是逆时针方向 3 那么我们就可以来推没一次出去的人的在剩下中是第几个。
764 0