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 ...
随机推荐
- 【尺度不变性】An Analysis of Scale Invariance in Object Detection – SNIP 论文解读
前言 本来想按照惯例来一个overview的,结果看到1篇十分不错而且详细的介绍,因此copy过来,自己在前面大体总结一下论文,细节不做赘述,引用文章讲得很详细,另外这篇paper引用十分详细,如果做 ...
- Jenkins-Kubernetes-docker-自动发布
使用的是Jenkins pipeline: 这里只是做了更新,没有创建,没有借助helm等工具,先用着,以后再研究. pipeline { agent any stages { stage(" ...
- spring boot 国际化MessageSource
转自:https://blog.csdn.net/flowingflying/article/details/76358970 spring中ResourceBundleMessageSource的配 ...
- 查看linux 之mysql 是否安装的几种方法
转自:https://jingyan.baidu.com/album/86112f1378bf282737978730.html?picindex=2 linux下怎么启动mysql服务 https: ...
- mac下安装c++开发环境
mac下安装c++开发环境 1 注册apple id 按照apple注册步骤注册apple id,我注册时遇到如下问题 apple store完成创建apple id步骤中,选择付款方式和账单地址后, ...
- PostgreSQL pg_hba.conf 文件简析
作者:高张远瞩(HiLoveS) 博客:http://www.cnblogs.com/hiloves/ 转载请保留该信息 最近试用PostgreSQL 9.04,将pg_hba.conf配置的一些心得 ...
- 轻量级 HTTP(s) 代理 TinyProxy
J CentOS 下安装 TinyProxy yum install -y tinyproxy 启动.停止.重启 # 启动service tinyproxy start# 停止service ti ...
- panda2
pandas是python为数据分析建造的可靠工具,很多地方和R语言有想通之处.数据分析并不是工具越高深越好,excel,R,python都是针对不同情况的不同工具,各有各的优缺点,就像你要搭一个架子 ...
- spring mvc: xml生成
spring mvc: xml生成 准备: javax.xml.bind.annotation.XmlElement; javax.xml.bind.annotation.XmlRootElement ...
- python PIL/Pillow图像扩展、复制、粘贴处理
http://blog.csdn.net/yuanyangsdo/article/details/60957685