Consider a network G=(V,E) G=(V,E) with source s s and sink t t . An s-t cut is a partition of nodes set V V into two parts such that s s and t t belong to different parts. The cut set is the subset of E E with all edges connecting nodes in different parts. A minimum cut is the one whose cut set has the minimum summation of capacities. The size of a cut is the number of edges in the cut set. Please calculate the smallest size of all minimum cuts.

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(最小割边最小割)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. hdu 6214 Smallest Minimum Cut[最大流]

    hdu 6214 Smallest Minimum Cut[最大流] 题意:求最小割中最少的边数. 题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦.. #incl ...

  4. HDU 6214.Smallest Minimum Cut 最少边数最小割

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

  5. HDU 6214 Smallest Minimum Cut 最小割,权值编码

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6214 题意:求边数最小的割. 解法: 建边的时候每条边权 w = w * (E + 1) + 1; 这 ...

  6. HDU 6214 Smallest Minimum Cut (最小割且边数最少)

    题意:给定上一个有向图,求 s - t 的最小割且边数最少. 析:设边的容量是w,边数为m,只要把每边打容量变成 w * (m+1) + 1,然后跑一个最大流,最大流%(m+1),就是答案. 代码如下 ...

  7. hdu 6214 Smallest Minimum Cut(最小割的最少边数)

    题目大意是给一张网络,网络可能存在不同边集的最小割,求出拥有最少边集的最小割,最少的边是多少条? 思路:题目很好理解,就是找一个边集最少的最小割,一个方法是在建图的时候把边的容量处理成C *(E+1 ...

  8. hdu 6214 : Smallest Minimum Cut 【网络流】

    题目链接 ISAP写法 #include <bits/stdc++.h> using namespace std; typedef long long LL; namespace Fast ...

  9. Smallest Minimum Cut HDU - 6214(最小割集)

    Smallest Minimum Cut Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Oth ...

随机推荐

  1. linux主机之间无密钥ssh访问

    ssh-keygen -t rsa ssh-copy-id -i /root/.ssh/id-rsa.pub root@10.0.0.109 # 实现和109互通 vim /etc/hosts DNS ...

  2. Flume实例一学习

    cp conf/flume-env.sh.template conf/flume-env.sh 打开flume-env.sh,配置Java环境变量 [root@test1 apache-flume-- ...

  3. POJ 2186 Popular Cows(强连通分量Kosaraju)

    http://poj.org/problem?id=2186 题意: 一个有向图,求出点的个数(任意点可达). 思路: Kosaraju算法的第一次dfs是后序遍历,而第二次遍历时遍历它的反向图,从标 ...

  4. vcf2maf

    1.https://github.com/mskcc/vcf2maf 2.https://github.com/cbare/vcf2maf

  5. SPA(单页面web应用程序)

    单页web应用(single page web application,SPA),就是只有一张web页面的应用,是加载单个HTML页面并在用户与应用程序交互时动态更新该页面的web应用程序. 浏览器一 ...

  6. HAproxy的安装配置及动静分离

    /////////////////////////////目录//////////////////////////////////////////一.安装HAproxy二.编写HAproxy启动脚本三 ...

  7. POJ1247-Magnificent Meatballs

    http://poj.org/problem?id=1247 Magnificent Meatballs Time Limit: 1000MS   Memory Limit: 10000K Total ...

  8. fio测试freenas共享的iscsi磁盘性能

    4k随机读iops: fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=randread -filename=/dev/sdb -iodepth=32 ...

  9. ffmpeg播放RTSP的一点优化

    简单记录一下最近使用ffmpeg播放RTSP做的一点参数优化. 先做如下定义: AVDictionary* options = NULL; 1.画质优化 原生的ffmpeg参数在对1920x1080的 ...

  10. Metasploit 使用简介

    Metasploit Framework 是非常优秀的开源渗透测试框架,像我这样的菜鸟刚刚听说,于是花时间好好研究了一下,整理了一下学习笔记,贴出来和大家一起交流.第一次写文章又不足的地方大家多多指点 ...