HDU6214 Smallest Minimum Cut【最小割-最小边数】
来源:互联网 发布:淘宝店家怎么代销 编辑:程序博客网 时间:2024/06/05 19:49
Smallest Minimum Cut
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 471 Accepted Submission(s): 172
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 casesT (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 from1 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
题意:给点一个有向图(n个点(n<=200)m条边(m<=1000)),求从s到t的最小割的最小边数。
思路:将每条边权值扩大大数MOD倍再加上1,所求最大流膜MOD即为答案。跑完最大流,假设在乘大数不加一的情况下,边容量为0即为割边,加1后,多跑的最大流即为最小割边的最小边数。(很奇怪,我用另外一种,先跑完最大流,然后根据容量新建边(cap为0建1,否则为INF)一直wa)
ACcode(Dinic)
#include<bits/stdc++.h>using namespace std;const int N=1000;const int MOD=100000;const int INF=0x3f3f3f3f;struct edge{ int to,cap,rev; edge(int x,int y,int z) { to=x;cap=y;rev=z; }};vector<edge> g[N];int level[N],iter[N],n,m,s,t;bool vis[N];void add(int from,int to,int cap){ g[from].push_back(edge(to,cap,g[to].size())); g[to].push_back(edge(from,0,g[from].size()-1));}void bfs(int s){ memset(level,-1,sizeof(level)); level[s]=0; queue<int> que; que.push(s); while(!que.empty()) { int v=que.front();que.pop(); for(int i=0;i<g[v].size();i++) { edge &e=g[v][i]; if(e.cap>0&&level[e.to]<0) { level[e.to]=level[v]+1; que.push(e.to); } } }}int dfs(int v,int t,int f){ if(v==t)return f; for(int &i=iter[v];i<g[v].size();i++) { edge &e=g[v][i]; if(e.cap>0&&level[e.to]>level[v]) { int d=dfs(e.to,t,min(f,e.cap)); if(d>0) { e.cap-=d; g[e.to][e.rev].cap+=d; return d; } } } return 0;}int max_flow(int s,int t){ int flow=0; while(1) { bfs(s); if(level[t]<0)return flow; memset(iter,0,sizeof(iter)); int f; while(f=dfs(s,t,INF)) { flow+=f; } }}int main(){ int TA,x,y,z; scanf("%d",&TA); while(TA--) { scanf("%d%d%d%d",&n,&m,&s,&t); for(int i=1;i<=n;i++) g[i].clear(); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); z=z*MOD+1; add(x,y,z); } printf("%d\n",max_flow(s,t)%MOD); } return 0;}
阅读全文
0 0
- HDU6214 Smallest Minimum Cut【最小割-最小边数】
- HDU6214 Smallest Minimum Cut 【最大流求最小割边】
- hdu6214-最小割边数&最大流最小割-Smallest Minimum Cut
- hdu6214—Smallest Minimum Cut(最小割的最少割边)
- HDU6214 Smallest Minimum Cut 最小割/最少边 [2017 ACM/ICPC Asia Regional Qingdao Online]
- hdu6214 Smallest Minimum Cut(最小割求割边数)
- hdu6214 Smallest Minimum Cut 最小割边数
- hdu Smallest Minimum Cut 边数最少的最小割
- 【2017青岛网络赛】1009 Smallest Minimum Cut hdu6214 最小割 最大流模版
- HDU 6214 Smallest Minimum Cut【最小割的最小边数】
- HDU 6214 Smallest Minimum Cut 【最小割】
- HDU-6214 Smallest Minimum Cut(最小割)
- HDU 6214 Smallest Minimum Cut(网络流 最小割最少边数)
- HDU 6214 Smallest Minimum Cut(求最小割的最少边数)
- hdu6214-最小割集中边数最少
- HDU 6214 Smallest Minimum Cut (最小割最小割边)(两种算法的分析)
- HDU 6214 Smallest Minimum Cut 2017青岛网赛1009(最小割最小割边)
- 2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
- zookeeper快速入门
- 2017年9月17日训练日记
- jsp基础(二)
- Ubuntu安装JDK
- Spring事务配置的五种方式
- HDU6214 Smallest Minimum Cut【最小割-最小边数】
- NYOJ 22
- [MYSQL -15]创建联结
- 九度 题目1482:玛雅人的密码
- 【前端工程化之学习总结】
- Android USB-HID controlTransfer() 参数详解
- 数据结构编程笔记二十七:第十章 内排序 各种排序算法的实现
- Redis原理详解
- Turn to 博客园