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 本地调试Hadoop

    将Hadoop部署后,可以使用java api进行访问,但是并不能像安装完mysql后用python自带的mysql api连接那么简单. Hadoop/share目录下有Hadoop所有的jar包, ...

  2. less文件的运行

    例:在任意处创建一个.less文件,比如在桌面2017.06.28文件中创建了一个main.less文件,然后通过命令行编译main.less,步骤: win+R,cmd打开命令面板,切换到main. ...

  3. Java线程池可用的队列

    Java线程池ThreadPoolExecutor的构造器: public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long ...

  4. 为什么我们选择parquet

    说明:此方案已经我们已经运行1年. 1.场景描述: 我们对客户登录日志做了数据仓库,但实际业务使用中有一些个共同点, A  需要关联维度表 B  最终仅取某个产品一段时间内的数据 C 只关注其中极少的 ...

  5. mongo docker image

    mongo 保存压缩镜像 docker save -o ~/Desktop/mongo.tar mongo 7za a -mx=9 ~/Desktop/mongo.tar{.7z,} 导入或拉取镜像 ...

  6. Matlab 一些函数

    max(A,[],dim):dim取1或2.dim取1时,该函数和max(A)完全相同:dim取2时,该函数返回一个列向量,其第i个元素是A矩阵的第i行上的最大值.

  7. BZOJ 1005 [HNOI2008]明明的烦恼 ★(Prufer数列)

    题意 N个点,有些点有度数限制,问这些点可以构成几棵不同的树. 思路 [Prufer数列] Prufer数列是无根树的一种数列.在组合数学中,Prufer数列是由一个对于顶点标过号的树转化来的数列,点 ...

  8. 卸载Linux自带的JDK

    Redhat Enterprise Linux中自带了jdk的旧版本,往往需要卸载,卸载步骤如下: 在终端输入:yum remove java 终端显示:Is this ok[y/N]: 输入y,按回 ...

  9. iOS-如何写好一个UITableView

    如何写好一个UITableView 字数5787 阅读3745 评论25 喜欢69 本文是直播分享的简单文字整理,直播共分为上.下两部分.第一部分:优酷 Or YouTube,第二部分:优酷 Demo ...

  10. python2 commands模块在python3.x被subprocess取代

    subprocess 可以执行shell命令的相关模块和函数有: os.systemos.spawnos.popen --废弃popen2.* --废弃commands.* --废弃,3.x中被移除 ...