2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
来源:互联网 发布:web动画创建软件 编辑:程序博客网 时间:2024/05/19 15:22
传送门:点击打开链接
Smallest Minimum Cut
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 234 Accepted Submission(s): 64
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
Source
2017 ACM/ICPC Asia Regional Qingdao Online
示例看了好长时间,以为简单的跑最大流,发现每次的最大流都是3,后来才看出来是满足最大流情况下删除的最少的边数。最小割转化为最大流问题,用到一个定理: 删除的边一定会是最大流跑完之后满流的边,然后将这几条边再重新赋值为最大,再跑一遍最大流得到结果。
dinic过不了啊,tle7次啊,差一点进不了现场赛啊!只能有高效的SAP,跑600次最大流,时间从超时瞬间降到265ms,神奇的不止这些。听说1003简单kmp就能过,什么鬼?队友花样错了十几次,命啊。
代码实现:
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<cstdio>#define ll int#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=2005;const int maxm=10005;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};struct Edge{ int v,next; ll cap;}edge[maxm];int head[maxn],pre[maxn],cur[maxn],level[maxn],gap[maxn],NV,cnt,n,m;void Insert(int u,int v,ll cap){ edge[cnt].v=v;edge[cnt].cap=cap; edge[cnt].next=head[u];head[u]=cnt++; edge[cnt].v=u;edge[cnt].cap=0; edge[cnt].next=head[v];head[v]=cnt++;}ll SAP(int start,int END){ mset(pre,-1); mset(level,0); mset(gap,0); for(int i=0;i<=NV;i++)cur[i]=head[i]; int u=pre[start]=start; ll aug=-1,maxflow=0; gap[0]=NV; while(level[start]<NV){q: for(int &i=cur[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(edge[i].cap&&level[u]==level[v]+1){ aug==-1?aug=edge[i].cap:aug=min(aug,edge[i].cap); pre[v]=u; u=v; if(v==END){ maxflow+=aug; for(u=pre[u];v!=start;v=u,u=pre[u]){ edge[cur[u]].cap-=aug; edge[cur[u]^1].cap+=aug; } aug=-1; } goto q; } } int minlevel=NV; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].v; if(edge[i].cap&&minlevel>level[v]){ cur[u]=i; minlevel=level[v]; } } if(--gap[level[u]]==0)break; level[u]=minlevel+1; gap[level[u]]++; u=pre[u]; } return maxflow;}int main(){ int T,u,v,w,flag,start,END; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); scanf("%d%d",&start,&END);NV=n,cnt=0; memset(head,-1,sizeof(head)); for(int i=1;i<=m;i++){ scanf("%d%d%d",&u,&v,&w); if(u==v) continue; Insert(u,v,(ll)w*maxm+1); } ll ans=SAP(start,END); printf("%d\n",ans%maxm); } return 0;}
阅读全文
0 0
- 2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
- HDU6214 Smallest Minimum Cut 最小割/最少边 [2017 ACM/ICPC Asia Regional Qingdao Online]
- 【2017 ACM/ICPC Asia Regional Qingdao Online 1009】hdu 6214 Smallest Minimum Cut
- HDU-2017 ACM/ICPC Asia Regional Qingdao Online-1009-Smallest Minimum Cut
- 2017 ACM/ICPC Asia Regional Qingdao Online Smallest Minimum Cut 网络流
- HDU 5889 Barricade (最小割) 2016 ACM/ICPC Asia Regional Qingdao Online
- 2016 ACM/ICPC Asia Regional Qingdao Online hdu 5889 Barricade (最短路+最小割)
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
- HDu 6216 && 2017 ACM/ICPC Asia Regional Qingdao Online 1011
- HDU-2017 ACM/ICPC Asia Regional Qingdao Online-1001-Apple
- HDU-2017 ACM/ICPC Asia Regional Qingdao Online-补题
- 2017 ACM/ICPC Asia Regional Qingdao Online
- 2017 ACM/ICPC Asia Regional Qingdao Online
- 2017 ACM/ICPC Asia Regional Qingdao Online
- 2017 ACM/ICPC Asia Regional Qingdao Online
- 2017 ACM/ICPC Asia Regional Qingdao Online 1011(数学知识)
- hdu Smallest Minimum Cut 边数最少的最小割
- HDU 6211 Pythagoras (预处理, 2017 ACM/ICPC Asia Regional Qingdao Online)
- 46muduo库使用示例(五)
- 第三周项目二 建设“顺序表”算法库
- centos启动_某个开机启动的服务有问题导致不能启动
- (青岛站)1011
- 无限轮播
- 2017 ACM/ICPC Asia Regional Qingdao Online HDU 6214 Smallest Minimum Cut(最小割的边数)
- Maven安装、配置及如何集成到eclipse中
- pat 乙级 1071. 小赌怡情(15)
- Mapped Statements collection already contains value for……
- #Git 使用
- DS18b20温度传感器的使用
- C语言基础
- ubuntu 安装tomcat
- JAVASE3