Problem Description

Consider a network G=(V,E) with source s and sink t . An s-t cut is a partition of nodes set V into two parts such that s and t belong to different parts. The cut set is the subset of 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.
 
Input
The input contains several test cases and the first line is the total number of cases T (1≤T≤300) .
Each case describes a network G

, and the first line contains two integers n (2≤n≤200)

and m (0≤m≤1000)

indicating the sizes of nodes and edges. All nodes in the network are labelled from 1

to n

.
The second line contains two different integers s

and t (1≤s,t≤n)

corresponding to the source and sink.
Each of the next m

lines contains three integers u,v

and w (1≤w≤255)

describing a directed edge from node u

to v

with capacity w

.

 

Output

For 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
 
Source
 
【题意】: 求最小割中最少的边数。
【代码】:在建图时,每个边权乘以一个大的数E,然后加1,求出最大流后对E取模,就可以得到边数。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<sstream>
#include<cctype>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std; typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-;
const int INF=0x3f3f3f3f;
const int maxn=; int T;
int n,m,s,t;
int ans,flag,tot; int head[maxn],path[maxn],vis[maxn]; struct Edge
{
int from,to;
int cap;
int next;
}e[maxn]; void init()
{
tot=;
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
memset(path,,sizeof(path));
} void add_edge(int u,int v,int w)
{
e[tot].from=u;
e[tot].to=v;
e[tot].cap=w;
e[tot].next=head[u];
head[u]=tot++;
} int bfs()
{
queue<int>q;
q.push(s);
vis[s]=;
path[s]=-;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=head[u];i!=-;i=e[i].next)
{
int v=e[i].to;
if(e[i].cap>&&!vis[v])
{
path[v]=i;
vis[v]=;
if(v==t)
return ;
q.push(v);
}
}
}
return ;
} int EK()
{
int maxFlow=;
int flow,i;
while(bfs())
{
memset(vis,,sizeof(vis));
i=path[t];
flow=INF;
while(i!=-)
{
flow=min(flow,e[i].cap);
i=path[e[i].from];
}
i=path[t];
while(i!=-)
{
e[i].cap-=flow;
e[i^].cap+=flow;
i=path[e[i].from];
}
maxFlow+=flow;
}
return maxFlow;
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
scanf("%d%d",&s,&t);
for(int i=;i<m;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add_edge(a,b,c*+);
add_edge(b,a,);
}
printf("%d\n",EK()%);
}
return ;
}

E  K

最新文章

  1. iOS开发_数据存储方式
  2. css3新特性@media(媒体查询)
  3. Java多线程系列--“JUC锁”08之 共享锁和ReentrantReadWriteLock
  4. MySQL数据库初用(5.6版本)第一课
  5. Spring Autowired错误???
  6. [C/C++基础] C语言常用函数memset的使用方法
  7. iPhone播放音乐
  8. 华硕电脑安装ubuntu出现问题及决方案
  9. static int和static final int的区别
  10. 淘宝的ip地址库
  11. Running an etcd cluster on localhost
  12. String对象之间的比较
  13. 1003 Crashing Balloon
  14. windows下使用lighttpd+php(fastcgi)+mysql
  15. 第三十讲:Android之Animation(五)
  16. HDU1115--Lifting the Stone(求凸多边形的重心)
  17. Windows环境下google protobuf入门
  18. word中利用宏替换标点标点全角与半角
  19. whereis 命令详解
  20. 防XXS和SQL注入

热门文章

  1. [CF1031E]Triple Flips
  2. BZOJ1558 [JSOI2009]等差数列 【线段树】
  3. 统计无符号整数二进制中1的个数(Hamming weight)
  4. WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ
  5. CI框架浅析
  6. IDEA 用maven创建web项目编译时不能发布resources中的文件
  7. 前端部署: nginx配置
  8. nginx解决超长请求串(413 request Entity too Large错误解决办法)
  9. HDU 1877 又一版 A+B(进制转换)
  10. 【BZOJ3942】Censoring [KMP]