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. Learning Perl 第六章习题第一题

    按照first name找last name 知识点: 1. hash的使用和初始化 2. 使用exists函数检测hash中的键是否存在

  2. 删除Rancher节点的正确姿势

    在Rancher上疏散该节点 删除节点 登录该节点宿主机,删除rancher相关容器 docker rm -f -v $(docker ps -aq) 删除该节点的所有volume docker vo ...

  3. ubuntu16.04 安装power shell

    ubuntu16.04 安装power shell # Download the Microsoft repository GPG keys wget -q https://packages.micr ...

  4. 通栏banner自适应各个设备

    思路:图片不要设置为div的background,因为你设置了background-size,但是div的height没设置一样没用,除非你搞个js判断,动态刷新. 换一种思路,直接用<img& ...

  5. 字体渲染技术(字体抗锯齿技术) -webkit-font-smoothing: antialiased;

    1.-webkit-font-smoothing控制的字体渲染只对MacOS的webkit有效.所以,你在MacOS测试环境下面设置-webkit-font-smoothing时,只要你不把它设置为n ...

  6. SQL生成两个时间之间的所有日期

    select dateadd(dd,number,'2012-1-1') AS date from master..spt_values where type='p' and dateadd(dd,n ...

  7. JavaScript权威指南--类型、值和变量

    本章要点图 数据类型:计算机程序的运行需要对值(value)比如数字3.14或者文本"hello world"进行操作,在编程语言中,能够表示并操作的值的类型叫做数据类型(type ...

  8. 【原创】Centos 7利用软件Raid搭建ISCSI过程

    测试机器安装了4块2T硬盘,一块320G硬盘,利用320G硬盘安装CentOS 7系统,在CentOS 7系统上利用4块2T硬盘组建Raid 0,再配置iSCSI存储.注意,本文中的RAID指的是软R ...

  9. C# 获取命名空间对应的程序集位置

    由于同名命名空间会被多个程序集使用,C#没有提供直接的方法(对象浏览器也不行)通过命名空间获得程序集位置,这样就不方便找到那些引用文件时什么. 那么可以在立即窗口,中断某个代码的时候,去查询类所在程序 ...

  10. HDU1595-最短路-删边

    find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/32768 ...