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

HDU 6214 Smallest Minimum Cut 【网络流最小割+ 二种方法只能一种有效+hdu 3987原题】的更多相关文章

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

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

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

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

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

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

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

  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 【网络流】

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

  8. 2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数

    先最大流跑一遍 在残存网络上把满流边容量+1 非满流边容量设为无穷大 在进行一次最大流即可 (这里的边都不包括建图时用于反悔的反向边) #include<cstdio> #include& ...

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

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

随机推荐

  1. C#怎么调用方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Exep ...

  2. 51nod1254 最大子段和 V2 DP

    ---题面--- 题解: 表示今天做题一点都不顺.... 这题也是看了题解思路然后自己想转移的. 看的题解其实不是这道题,但是是这道题的加强版,因为那道题允许交换k对数. 因为我们选出的是连续的一段, ...

  3. 12.25模拟赛T3

    可以发现,答案O(根号)(因为链上答案最大,n/2,n/3...根号种) 每次求答案要二分 优秀的做法是: 对于小于根号n的暴力nlogn找,可能二分到同一个mid,记忆化一下最小的tot值 对于大于 ...

  4. UVA 11995 STL 使用

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

  5. Good Substrings CodeForces - 271D

    You've got string s, consisting of small English letters. Some of the English letters are good, the ...

  6. bzoj 1517 [POI2006]Met 贪心

    [POI2006]Met Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 203  Solved: 108[Submit][Status][Discus ...

  7. Java Web转发和重定向问题

    0x01:转发情况.转发过程中,只请求一次,request对象设置了之后会一直存在,直到下一次请求. 0x02:重定向情况.会发生两次请求,如果设置了request对象,那么重定向之后,request ...

  8. 【Foreign】置换 [数论][置换]

    置换 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 4 2 1 4 3 Sample O ...

  9. 51nod 扔盘子

    题目传送门 这道题一开始写了n方的算法 果不其然 它T了 所以就想想o(n)的算法 写不出来 就像sbzhq学习了一下 这道题啊 要维护一下从深度1到n每一段的最小值以及他的位置 然后就暴力搞一搞就o ...

  10. 【CF1027F】Session in BSU(dsu,基环树)

    题意:给出n场考试,每场考试有2天可以通过(第ai与bi天).每天最多参加一场考试,现在要求所有考试全部通过的最小天数 n<=1e6,1<=a[i]<b[i]<1e9 思路:F ...