博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 6214 Smallest Minimum Cut(最少边最小割)
阅读量:5034 次
发布时间:2019-06-12

本文共 3021 字,大约阅读时间需要 10 分钟。

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

题意

给你一个网络图,求最少边最小割

题解

如果流量全为1的话很容易知道最小边最小割=最小割

如果流量不为1,我们肯定要让哪里为1才可以得到答案

可以对边的权值进行hash,w-->w*hash+1

再跑最小割,跑完的答案%hash即可,这里hash>m就行

代码

1 #include
2 using namespace std; 3 4 const int maxn=1e5+5; 5 const int maxm=2e5+5; 6 int n,m,S,T; 7 int deep[maxn],q[400000]; 8 int FIR[maxn],TO[maxm],CAP[maxm],COST[maxm],NEXT[maxm],tote; 9 10 void add(int u,int v,int cap)11 {12 TO[tote]=v;13 CAP[tote]=cap;14 NEXT[tote]=FIR[u];15 FIR[u]=tote++;16 17 TO[tote]=u;18 CAP[tote]=0;19 NEXT[tote]=FIR[v];20 FIR[v]=tote++;21 }22 bool bfs()23 {24 memset(deep,0,sizeof deep);25 deep[S]=1;q[1]=S;26 int head=0,tail=1;27 while(head!=tail)28 {29 int u=q[++head];30 for(int v=FIR[u];v!=-1;v=NEXT[v])31 {32 if(CAP[v]&&!deep[TO[v]])33 {34 deep[TO[v]]=deep[u]+1;35 q[++tail]=TO[v];36 }37 }38 }39 return deep[T];40 }41 int dfs(int u,int fl)42 {43 if(u==T)return fl;44 int f=0;45 for(int v=FIR[u];v!=-1&&fl;v=NEXT[v])46 {47 if(CAP[v]&&deep[TO[v]]==deep[u]+1)48 {49 int Min=dfs(TO[v],min(fl,CAP[v]));50 CAP[v]-=Min;CAP[v^1]+=Min;51 fl-=Min;f+=Min;52 }53 }54 if(!f)deep[u]=-2;55 return f;56 }57 int maxflow()58 {59 int ans=0;60 while(bfs())61 ans+=dfs(S,1<<30);62 return ans;63 }64 void init()65 {66 tote=0;67 memset(FIR,-1,sizeof FIR);68 }69 int main()70 {71 int _;72 cin>>_;73 while(_--)74 {75 init();76 cin>>n>>m>>S>>T;77 for(int i=0,u,v,w;i
>u>>v>>w;80 add(u,v,w*1001+1);81 }82 printf("%d\n",maxflow()%1001);83 }84 return 0;85 }

 

转载于:https://www.cnblogs.com/taozi1115402474/p/9545150.html

你可能感兴趣的文章
java 字符串转json,json转对象等等...
查看>>
网站访问者UA检测及跳转
查看>>
eclipse中集成maven
查看>>
word2010中如何去掉标题前面的小黑点
查看>>
极客前端部分题目收集【索引】
查看>>
第四天 selenium的安装及使用
查看>>
关于js的设计模式(简单工厂模式,构造函数模式,原型模式,混合模式,动态模式)...
查看>>
KMPnext数组循环节理解 HDU1358
查看>>
5、散列表
查看>>
团队作业---软件制作10
查看>>
你拥有的最宝贵的财富是什么?(通向财富自由学习笔记三)
查看>>
tomcat 启动正常访问却是 404
查看>>
android调试debug快捷键
查看>>
【读书笔记】《HTTP权威指南》:Web Hosting
查看>>
Inoodb 存储引擎
查看>>
数据结构之查找算法总结笔记
查看>>
Linux内核OOM机制的详细分析
查看>>
Android TextView加上阴影效果
查看>>
Android开源框架AsyncHttpClient (android-async-http)使用
查看>>
Requests库的基本使用
查看>>