最小割-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 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 ≤ N ≤ 500, 0 ≤ M ≤ N × (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 ∈V,MinCut=min(s-t最小割,将s与v缩点之后的MinCut)。在此不予证明。

Stoer-Wagner 算法流程:

1. 初始置最小割MinCut 为INT_MAX。

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

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

----缩点操作:

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

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

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

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

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

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

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

最小割-poj-2914

时间: 2024-07-29 22:46:29

最小割-poj-2914的相关文章

poj 2914 Minimum Cut 无向图最小边割

题意: 求无向图的全局最小边割. 分析: stoer-wagner模板. 代码: //poj 2914 //sep9 #include <iostream> using namespace std; const int maxN=512; int g[maxN][maxN]; int b[maxN],dist[maxN]; int n,m; int Min_Cut_Phase(int ph,int &x,int &y) { int i,j,t; t=1; b[1]=ph; fo

POJ 2914 Minimum Cut (全局最小割)

[题目链接] http://poj.org/problem?id=2914 [题目大意] 求出一个最小边割集,使得图不连通 [题解] 利用stoerwagner算法直接求出全局最小割,即答案. [代码(递归)] #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int INF=0x3f3f3f3f; const int MAX_N=510; int v

POJ 2914 Minimum Cut 最小割算法题解

最标准的最小割算法应用题目. 核心思想就是缩边:先缩小最大的边,然后缩小次大的边,依此缩小 基础算法:Prime最小生成树算法 不过本题测试的数据好像怪怪的,同样的算法时间运行会差别很大,而且一样的代码替换,居然会WA.系统出错的几率很小,难倒测试系统本题会有错误? 懒得继续测试这道题的系统了,反正算法正确,AC. #include <stdio.h> #include <string.h> #include <limits.h> const int MAX_N = 5

POJ 2914 Minimum Cut 全局最小割

裸的全局最小割了吧 有重边,用邻接矩阵的时候要小心 #include<iostream> #include<cstdio> #include<bitset> #include<cstring> #define MOD 1000000007 #define maxn 509 using namespace std; int a[590][590],wage[maxn],in[maxn],vis[maxn]; int n,x,y,v; int find(int&

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 co

POJ 2914 - Minimum Cut - 全局最小割,Stoer-Wagner算法

题目大意:给定一个N个点.M条边的无向带权图,边的权值均为正整数.若要使它变成非连通图,需要移除的边总权值最小是多少? N≤500,图中不存在自环,但可能有重边(这里题意没交代清楚). Stoer-Wagner算法裸题.英文维基:https://en.wikipedia.org/wiki/Stoer%E2%80%93Wagner_algorithm 该算法的思想之一是:对于一个无向连通图,选定某两点s,t,以及该图的一个s-t割C,则"C是该图的全局最小割"是"C是s-t的最

poj 3308 Paratroopers 最小割 最小点权覆盖

题目链接:http://poj.org/problem?id=3308 题意: 有一个M*N的图,上面的一些点上有伞兵. 可以设置一些枪在每行或者每列上,通过射击,这行或这列的伞兵就会被消灭.每个枪的设置有一个花费,如果设置多个枪,那么花费是设置每个枪的乘积. 问消灭所有伞兵最少的花费是多少. 思路: 每个点的伞兵至少要用那一列或者那一行设置的枪去消灭,那么就可以应用点覆盖的模型.把伞兵看成是一条边,这条边至少要用一个点来覆盖. 而题目中最终花费是所有花费的乘积,那么可以用对数log(x)+lo

POJ 3469 Dual Core CPU(最小割)

POJ 3469 Dual Core CPU 题目链接 题意:有a,b两台机器,有n个任务,在a机器和b机器需要不同时间,给定m个限制,如果u, v在不同机器需要额外开销,问最小开销 思路:最小割,源点为a机器,汇点为b机器,这样的话求出最小割,就是把点分成两个集合的最小代价,然后如果u, v在不同机器需要开销,则连u,v v,u两条边,容量为额外开销,这样如果这条边是割边,则a,b会在不同集合,并且代价就会被加上去 代码: #include <cstdio> #include <cst

POJ 1815 Friendship(最小割)

http://poj.org/problem?id=1815 Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 9026   Accepted: 2534 Description In modern society, each person has his own friends. Since all the people are very busy, they communicate with eac

poj 1815 Friendship 字典序最小+最小割

题目链接:http://poj.org/problem?id=1815 In modern society, each person has his own friends. Since all the people are very busy, they communicate with each other only by phone. You can assume that people A can keep in touch with people B, only if 1. A kno