【2017青岛网络赛】1009 Smallest Minimum Cut hdu6214 最小割 最大流模版
来源:互联网 发布:工程预算软件大全 编辑:程序博客网 时间:2024/06/06 01:45
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 networkG , 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 integerss and t (1≤s,t≤n) corresponding to the source and sink.
Each of the nextm lines contains three integers u,v and w (1≤w≤255) describing a directed edge from node u to v with capacity w .
Each case describes a network
The second line contains two different integers
Each of the next
Output
For each test case, output the smallest size of all minimum cuts in a line.
Sample Input
24 51 41 2 31 3 12 3 12 4 13 4 24 51 41 2 31 3 12 3 12 4 13 4 3
Sample Output
23
思路:
原题。。。
最小割=最大流
建图时,每条边的容量*k+1(k为任意一个大于容量的数。
最小割的最少边数为当前图的最小割%k。
因为原图的最小割中,只有边数最少的最小割才是现在的最小割。
现在的最小割=原图的最小割*k+边数。
#include<cstdio>#include<cstring>#include<queue>#include<cmath>using namespace std;const int Ni = 1100;const int MAX = 1<<26;struct Edge{ int u,v,c; int next;}edge[20*Ni];int n,m;int edn;//边数int p[Ni];//父亲int d[Ni];int sp,tp;//原点,汇点void addedge(int u,int v,int c){ edge[edn].u=u; edge[edn].v=v; edge[edn].c=c; edge[edn].next=p[u]; p[u]=edn++; edge[edn].u=v; edge[edn].v=u; edge[edn].c=0; edge[edn].next=p[v]; p[v]=edn++;}int bfs(){ queue <int> q; memset(d,-1,sizeof(d)); d[sp]=0; q.push(sp); while(!q.empty()) { int cur=q.front(); q.pop(); for(int i=p[cur];i!=-1;i=edge[i].next) { int u=edge[i].v; if(d[u]==-1 && edge[i].c>0) { d[u]=d[cur]+1; q.push(u); } } } return d[tp] != -1;}int dfs(int a,int b){ int r=0; if(a==tp)return b; for(int i=p[a];i!=-1 && r<b;i=edge[i].next) { int u=edge[i].v; if(edge[i].c>0 && d[u]==d[a]+1) { int x=min(edge[i].c,b-r); x=dfs(u,x); r+=x; edge[i].c-=x; edge[i^1].c+=x; } } if(!r)d[a]=-2; return r;}int dinic(int sp,int tp){ int total=0,t; while(bfs()) { while(t=dfs(sp,MAX)) total+=t; } return total;}int main(){ int n,m,ncase,s,t; scanf("%d",&ncase); while(ncase--) { edn=0; memset(p,-1,sizeof(p)); scanf("%d%d",&n,&m); scanf("%d%d",&s,&t); sp = s,tp = t; for(int i = 0;i < m;i++){ int a,b,c; scanf("%d%d%d",&a,&b,&c); addedge(a, b, c*332+1); } printf("%d\n",dinic(sp,tp)%332); } return 0;}
阅读全文
1 0
- 【2017青岛网络赛】1009 Smallest Minimum Cut hdu6214 最小割 最大流模版
- hdu6214-最小割边数&最大流最小割-Smallest Minimum Cut
- HDU6214 Smallest Minimum Cut 【最大流求最小割边】
- 2017 青岛网络赛 Smallest Minimum Cut 最大流最小割问题, (加深理解最大流问题)
- HDU 6214 Smallest Minimum Cut 2017青岛网赛1009(最小割最小割边)
- HDU6214 Smallest Minimum Cut【最小割-最小边数】
- HDU6214 Smallest Minimum Cut【网络流】
- HDU6214 Smallest Minimum Cut 最小割/最少边 [2017 ACM/ICPC Asia Regional Qingdao Online]
- Hdu 6214 Smallest Minimum Cut【Dinic-最大流最小割】
- hdu6214 Smallest Minimum Cut(最小割求割边数)
- hdu6214 Smallest Minimum Cut 最小割边数
- hdu6214—Smallest Minimum Cut(最小割的最少割边)
- HDU 6214 Smallest Minimum Cut(网络流 最小割最少边数)
- HDU 6214 Smallest Minimum Cut 【最小割】
- HDU-6214 Smallest Minimum Cut(最小割)
- HDU6214 2017青岛赛区网络赛
- HDU 6214 Smallest Minimum Cut(最小割的最少割边数)
- HDU 6214 Smallest Minimum Cut 最小割(isap)
- loadrunner Web_类函数之Web_remove_auto_filter()
- MySQL数据的主从复制、半同步复制和主主复制详解
- hdu 6209 The Intersection
- SQL数据库简单语句操作
- 从FBTweak 源码剖析一些中阶知识
- 【2017青岛网络赛】1009 Smallest Minimum Cut hdu6214 最小割 最大流模版
- H5本地存储详细使用教程(localStorage + JSON数据存储应用框架)
- 计算机人物总结
- 监听EditText,跟随输入文字而变化,double类型取余小数点后两位
- 数据结构学习技巧
- HDU---1732 Push Box【BFS】
- 初窥nodejs(三) ——自定义模块
- phpcms转到https后无法注册问题的解决
- 在Ubuntu 17.04下安裝ROS