HDU - 6214:Smallest Minimum Cut(最小割边最小割)
InputThe input contains several test cases and the first line is the total number of cases T (1≤T≤300) T (1≤T≤300) .
Each case describes a network G G
, and the first line contains two integers n (2≤n≤200) n (2≤n≤200)
and m (0≤m≤1000) m (0≤m≤1000)
indicating the sizes of nodes and edges. All nodes in the network are labelled from 1 1
to n n
.
The second line contains two different integers s s
and t (1≤s,t≤n) t (1≤s,t≤n)
corresponding to the source and sink.
Each of the next m m
lines contains three integers u,v u,v
and w (1≤w≤255) w (1≤w≤255)
describing a directed edge from node u u
to v v
with capacity w w
.OutputFor each test case, output the smallest size of all minimum cuts in a line.Sample Input
2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 2
4 5
1 4
1 2 3
1 3 1
2 3 1
2 4 1
3 4 3
Sample Output
2
3
题意:给定N点M边的网络,求最小割边的数量,使得S与T不连通。
思路:百度才知道的。用了数学的思想来搞的,每条边的容量V=V*(M+1)+1,最后的最小割=ans/(M+1),最小割边=ans%(M+1);
简单说明:肯定是对的,因为V=V*(M+1)+1的这个尾巴“1”数量少于M+1,所以ans/(M+1)显然不会进位,就等于最小割;那么尾巴1的个数就是边数了,ans膜一下(M+1)最小割求出的最少边数。
#include<bits/stdc++.h>
using namespace std;
const int maxn=;
const int inf=0x7fffffff;
int vd[maxn],dis[maxn],Laxt[maxn],Next[maxn],To[maxn],V[maxn];
int N,M,cnt,ans,S,T;
void update()
{
for(int i=;i<=N;i++) Laxt[i]=vd[i]=dis[i]=;
for(int i=;i<=cnt;i++) V[i]=;
cnt=; ans=;
}
void add(int u,int v,int c)
{
Next[++cnt]=Laxt[u];Laxt[u]=cnt;To[cnt]=v;V[cnt]=c;
Next[++cnt]=Laxt[v];Laxt[v]=cnt;To[cnt]=u;V[cnt]=;
}
int sap(int u,int flow)
{
int tmp,delta=;
if(flow==||u==T) return flow;
for(int i=Laxt[u];i;i=Next[i])
{
if(dis[To[i]]+==dis[u]&&V[i]>){
tmp=sap(To[i],min(flow-delta,V[i]));
V[i]-=tmp; V[i^]+=tmp; delta+=tmp;
if(delta==flow||dis[S]>=N) return delta;
}
}
vd[dis[u]]--;
if(vd[dis[u]]==) dis[S]=N;
vd[++dis[u]]++;
return delta;
}
int main()
{
int C,i,j,u,v,w;
scanf("%d",&C);
while(C--){
scanf("%d%d%d%d",&N,&M,&S,&T);
update();
for(i=;i<=M;i++){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w*(M+)+);
}
while(dis[S]<N) ans+=sap(S,inf);
printf("%d\n",ans%(M+));
}
return ;
}
HDU - 6214:Smallest Minimum Cut(最小割边最小割)的更多相关文章
- HDU 6214 Smallest Minimum Cut(最少边最小割)
Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition o ...
- HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】
Problem Description Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition ...
- hdu 6214 Smallest Minimum Cut[最大流]
hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...
- HDU 6214.Smallest Minimum Cut 最少边数最小割
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
- HDU 6214 Smallest Minimum Cut 最小割,权值编码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...
- HDU 6214 Smallest Minimum Cut (最小割且边数最少)
题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...
- hdu 6214 Smallest Minimum Cut(最小割的最少边数)
题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...
- hdu 6214 : Smallest Minimum Cut 【网络流】
题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...
- Smallest Minimum Cut HDU - 6214(最小割集)
Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Oth ...
随机推荐
- mvn deploy返回400错误的几种可能
user credentials are wrong url to server is wrong user does not have access to the deployment reposi ...
- jsplumb 的初次使用
最近的项目要能创建流程, 流程配置什么的就找了 jsplumb 来做流程的显示配置.经过两天的研究成果已经很明显了 参考了以下一些大神们的博客: jsplumb 中文教程 连线绘图工具库介绍 附简单在 ...
- 嵌入式 Web workers
前言 虽然worker可以将复杂的运算放入单独线程去运算,不阻塞UI线程,但是,由于worker()的构造函数的参数不能读取本地的文件,只能来自网络,所以当在一个项目里想使用本地的模块函数,是一个很麻 ...
- Sql Server中的DBCC命令详细介绍
一:DBCC 1:什么是DBCC 我不是教学老师,我也说不到没有任何无懈可击的定义,全名:Database Console Commands.顾名思义“数据库控制台命令”,说到“控制台“,我第一反应就 ...
- LR简单解析
- SPOJ KPSUM ★(数位DP)
题意 将1~N(1<=N<=10^15)写在纸上,然后在相邻的数字间交替插入+和-,求最后的结果.例如当N为12时,答案为:+1-2+3-4+5-6+7-8+9-1+0-1+1-1+2=5 ...
- python使用安装ipdb
1.安装 python3版本直接执行pip install ipdb命令安装 python2.7版本的需要指定ipdb的版本 pip install ipdb==0.10.2 等号后面的就是版本,因为 ...
- java和python互相调用
java和python互相调用 作者:xuaijun 日期:2017.1.1 python作为一种脚本语言,大量用于测试用例和测试代码的编写,尤其适用于交互式业务场景.实际应用中,很多网管系统 ...
- Java复习5.面向对象
Java 复习5面向对象知识 20131004 前言: 前几天整理了C++中的面向对象的知识,学习Java语言,当然最重要的就是面向对象的知识,因为可以说Java是最正宗的面向对象语言,相比C++,更 ...
- python 获取当前时间(关于time()时间问题的重要补充)
python 获取当前时间 我有的时候写程序要用到当前时间,我就想用python去取当前的时间,虽然不是很难,但是老是忘记,用一次丢一次,为了能够更好的记住,我今天特意写下python 当前时间这 ...