hdu 6124 Smallest Minimum Cut
来源:互联网 发布:js mouseover 编辑:程序博客网 时间:2024/05/22 12:53
Smallest Minimum Cut
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 83 Accepted Submission(s): 21
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
Source
2017 ACM/ICPC Asia Regional Qingdao Online
/*题意:求最小割中边数最少的边数题解:在建图时,每个边权乘以一个大的数E,然后加1,求出最大流后对E取模,就可以得到边数。*/#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace std;typedef long long ll;const ll maxv = 2000+10;const ll INF = 0x3f3f3f3f;struct edge{ ll to,cap,rev;};vector <edge> G[maxv];ll step[maxv];//从源点到点x的距离ll iter[maxv];//定点x的第几条边开始有用void add_edge(ll from, ll to, ll cap){ G[from].push_back((edge){to,cap,G[to].size()}); G[to].push_back((edge){from,0,G[from].size()-1});}void bfs(ll s){ memset(step,-1,sizeof(step)); step[s]=0; queue <ll> q; q.push(s); while(!q.empty()) { ll v=q.front(); q.pop(); for(ll i=0;i<G[v].size();++i) { edge &e = G[v][i]; if(e.cap>0 && step[e.to]<0) { step[e.to]=step[v]+1; q.push(e.to); } } }}ll dfs(ll v,ll t, ll f){ if(v==t) return f; for(ll &i=iter[v];i<G[v].size();++i)//这里是引用,i++的同时iter也++,其实相当于上个的used,不过不用判断了 { edge &e = G[v][i]; if(e.cap>0 && step[e.to]>step[v]) { ll d=dfs(e.to,t,min(e.cap,f)); if(d>0) { e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0;}ll max_flow(ll s,ll t){ ll flow =0; for(;;) { bfs(s); if(step[t]<0) return flow; memset(iter,0,sizeof(iter)); ll f; while((f = dfs(s,t,INF))>0) flow += f; }}ll n,m;ll s,t;ll w;int main(){ ll T; scanf("%lld",&T); while(T--){ scanf("%lld%lld",&n,&m); scanf("%lld%lld",&s,&t); for(ll i = 0;i<maxv;++i) G[i].clear(); for(ll i=0;i<m;++i){ ll c,d; scanf("%lld%lld%lld",&c,&d,&w); add_edge(c,d,w*1000+1); } printf("%lld\n",max_flow(s,t)%1000); } return 0;}
阅读全文
1 0
- hdu 6124 Smallest Minimum Cut
- Smallest Minimum Cut HDU
- 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(最小割的最少割边数)
- Hdu 6214 Smallest Minimum Cut【Dinic-最大流最小割】
- HDU 6214 Smallest Minimum Cut 最小割(isap)
- Smallest Minimum Cut(HDU 6214 dinic模板)
- HDU 6214 Smallest Minimum Cut (最小割)
- hdu Smallest Minimum Cut 边数最少的最小割
- Hdu 6214 Smallest Minimum Cut(最小割)
- hdoj 6214 Smallest Minimum Cut
- HDU 5631Minimum Cut-Cut
- hdu6214 Smallest Minimum Cut(最小割求割边数)
- HDU6214 Smallest Minimum Cut【网络流】
- hdu6214 Smallest Minimum Cut 最小割边数
- TensorFlow安装与入门: 使用CNN训练MNIST
- 大话设计模式之观察者模式
- web前端
- Maven项目疑难错误及解决方法
- PullToRefreshListView用法
- hdu 6124 Smallest Minimum Cut
- C/C++ 编译器优化
- java中正则表达式的使用
- (设计模式)单例模式-java
- redis集群搭建及注意事项
- Fibonacci数列
- 《简明python教程》学习笔记
- Tomcat集群中Session同步共享
- 自然语言处理之LDA主题模型(占坑)