hdu-6214 Smallest Minimum Cut(最小割的最少边)
来源:互联网 发布:吉利知豆汽车价格 编辑:程序博客网 时间:2024/05/22 00:06
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
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#define LL long long#define inf 0x3f3f3f3fusing namespace std;const int maxn=210;struct node{ int u,v,w,next;}edge[maxn*20];int n,m,sp,tp,k;int head[maxn];int d[maxn];void addedge(int u,int v,int w){ edge[k].u=u; edge[k].v=v; edge[k].w=w; edge[k].next=head[u]; head[u]=k++; edge[k].u=v; edge[k].v=u; edge[k].w=0; edge[k].next=head[v]; head[v]=k++;}int bfs(){ queue<int> q; memset(d,-1,sizeof(d)); d[sp]=0; q.push(sp); while(!q.empty()) { int a=q.front(); q.pop(); for(int i=head[a];i!=-1;i=edge[i].next) { int b=edge[i].v; if(d[b]==-1&&edge[i].w>0) { d[b]=d[a]+1; q.push(b); } } } return d[tp]!=-1;}LL dfs(int a,LL b){ LL r=0; if(a==tp)return b; for(int i=head[a];i!=-1&&r<b;i=edge[i].next) { int u=edge[i].v; if(edge[i].w>0&&d[u]==d[a]+1) { int x=min((LL)edge[i].w,b-r); x=dfs(u,x); r+=x; edge[i].w-=x; edge[i^1].w+=x; } } if(!r)d[a]=-2; return r;}LL dinic(int sp,int tp){ LL sum=0,t; while(bfs()) { while(t=dfs(sp,inf)) { sum+=t; } } return sum;}int main(){ int T; int u,v,w; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); scanf("%d%d",&sp,&tp); k=0; memset(head,-1,sizeof(head)); for(int i=0;i<m;i++) { scanf("%d%d%d",&u,&v,&w); addedge(u,v,w*1000+1); } printf("%lld\n",dinic(sp,tp)%1000); } return 0;}
- HDU 6214 Smallest Minimum Cut(最小割的最少割边数)
- hdu Smallest Minimum Cut 边数最少的最小割
- HDU 6214 Smallest Minimum Cut(求最小割的最少边数)
- hdu-6214 Smallest Minimum Cut(最小割的最少边)
- HDU 6214 Smallest Minimum Cut(网络流 最小割最少边数)
- HDU 6214 Smallest Minimum Cut (最小割最小割边)(两种算法的分析)
- hdu6214—Smallest Minimum Cut(最小割的最少割边)
- HDU 6214 Smallest Minimum Cut 【最小割】
- HDU-6214 Smallest Minimum Cut(最小割)
- HDU 6214 Smallest Minimum Cut 最小割(isap)
- HDU 6214 Smallest Minimum Cut (最小割)
- Hdu 6214 Smallest Minimum Cut(最小割)
- HDU 6214 Smallest Minimum Cut【最小割的最小边数】
- HDU 6214 Smallest Minimum Cut 2017青岛网赛1009(最小割最小割边)
- 2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
- Hdu 6214 Smallest Minimum Cut【Dinic-最大流最小割】
- HDU6214 Smallest Minimum Cut 最小割/最少边 [2017 ACM/ICPC Asia Regional Qingdao Online]
- HDU6214 Smallest Minimum Cut【最小割-最小边数】
- 【开发环境系列】关于conda管理Python开发环境,你需要知道的事
- SpringBoot -- 集成Elasticsearch
- 【机器学习】分类算法之决策树(Decision tree)
- hdu3440 House Man 差分约束系统 SPFA算法
- 高晓松三问阿里巴巴合伙人,为什么来 为什么留 为什么战
- hdu-6214 Smallest Minimum Cut(最小割的最少边)
- matlab字符串操作方法
- mysql之路第四篇
- 对Cloudera Hadoop多一些了解
- thinkphp5实战系列(二)前台模板的引入
- oracle_____对列的常用操作
- Java NIO与IO的区别
- 为什么Dialog不能用Application的Context
- DevExpress汉化方法详解(附资源)