HDU3987:Harry Potter and the Forbidden Forest(最小割边数)
来源:互联网 发布:外汇数据下载 编辑:程序博客网 时间:2024/05/17 06:14
Harry Potter and the Forbidden Forest
Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2272 Accepted Submission(s): 779
Problem Description
Harry Potter notices some Death Eaters try to slip into Castle. The Death Eaters hide in the most depths of Forbidden Forest. Harry need stop them as soon as.
The Forbidden Forest is mysterious. It consists of N nodes numbered from 0 to N-1. All of Death Eaters stay in the node numbered 0. The position of Castle is node n-1. The nodes connected by some roads. Harry need block some roads by magic and he want to minimize the cost. But it’s not enough, Harry want to know how many roads are blocked at least.
The Forbidden Forest is mysterious. It consists of N nodes numbered from 0 to N-1. All of Death Eaters stay in the node numbered 0. The position of Castle is node n-1. The nodes connected by some roads. Harry need block some roads by magic and he want to minimize the cost. But it’s not enough, Harry want to know how many roads are blocked at least.
Input
Input consists of several test cases.
The first line is number of test case.
Each test case, the first line contains two integers n, m, which means the number of nodes and edges of the graph. Each node is numbered 0 to n-1.
Following m lines contains information about edges. Each line has four integers u, v, c, d. The first two integers mean two endpoints of the edges. The third one is cost of block the edge. The fourth one means directed (d = 0) or undirected (d = 1).
Technical Specification
1. 2 <= n <= 1000
2. 0 <= m <= 100000
3. 0 <= u, v <= n-1
4. 0 < c <= 1000000
5. 0 <= d <= 1
The first line is number of test case.
Each test case, the first line contains two integers n, m, which means the number of nodes and edges of the graph. Each node is numbered 0 to n-1.
Following m lines contains information about edges. Each line has four integers u, v, c, d. The first two integers mean two endpoints of the edges. The third one is cost of block the edge. The fourth one means directed (d = 0) or undirected (d = 1).
Technical Specification
1. 2 <= n <= 1000
2. 0 <= m <= 100000
3. 0 <= u, v <= n-1
4. 0 < c <= 1000000
5. 0 <= d <= 1
Output
For each test case:
Output the case number and the answer of how many roads are blocked at least.
Output the case number and the answer of how many roads are blocked at least.
Sample Input
34 50 1 3 00 2 1 01 2 1 11 3 1 12 3 3 16 70 1 1 00 2 1 00 3 1 01 4 1 02 4 1 03 5 1 04 5 2 03 60 1 1 00 1 2 01 1 1 11 2 1 01 2 1 02 1 1 1
Sample Output
Case 1: 3Case 2: 2Case 3: 2
Author
aMR @ WHU
Source
2011 Multi-University Training Contest 15 - Host by WHU
题意:给个图,求出最小割下的最少割边数。思路:首先最小割=最大流,如何求最少边数呢?原最小割为a,所有边权+1后跑最小割为b,b-a即是答案,因为边数多的流量仍然被边数少的限制了。为了方便起见我们把边权扩大K倍再+1,这样子求出最小割%K就是答案了,K为多少才合适呢?我们%K时得保证+1后增加的流量<K,不然取模就错误没意义了,极端情况下+1后增加的流量为边数,那么我们把K设为边数+1就行。
SAP from kuangbin:
# include <iostream># include <cstring># include <cstdio># include <algorithm>using namespace std;typedef long long LL;const int MAXN = 2e4;const int MAXM = 4e5+30;const LL INF = 0x3f3f3f3f3f3f3f3f;inline void s(int &ret){ char c; ret=0; while((c=getchar())<'0'||c>'9'); while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}struct Edge{ int to, next; LL cap, flow;}edge[MAXM];int tot, head[MAXN], gap[MAXN], dep[MAXN], pre[MAXN], cur[MAXN];void init(){ tot = 0; memset(head, -1, sizeof(head));}void add(int u, int v, LL w, LL rw=0){ edge[tot] = {v, head[u], w, 0}; head[u] = tot++; edge[tot] = {u, head[v], rw, 0}; head[v] = tot++;}LL SAP(int start, int End, int N){ memset(gap, 0, sizeof(gap)); memset(dep, 0, sizeof(dep)); memcpy(cur, head, sizeof(head)); int u = start; pre[u] = -1; gap[0] = N; LL ans = 0; while(dep[start] < N) { if(u == End) { LL Min = INF; for(int i = pre[u];i != -1; i = pre[edge[i^1].to]) if(Min > edge[i].cap - edge[i].flow) Min = edge[i].cap - edge[i].flow; for(int i = pre[u];i != -1; i = pre[edge[i^1].to]) { edge[i].flow += Min; edge[i^1].flow -= Min; } u = start; ans += Min; continue; } bool flag = false; int v; for(int i = cur[u]; i != -1;i = edge[i].next) { v = edge[i].to; if(edge[i].cap - edge[i].flow && dep[v]+1 == dep[u]) { flag = true; cur[u] = pre[v] = i; break; } } if(flag) { u = v; continue; } int Min = N; for(int i = head[u]; i != -1;i = edge[i].next) if(edge[i].cap - edge[i].flow && dep[edge[i].to] < Min) { Min = dep[edge[i].to]; cur[u] = i; } gap[dep[u]]--; if(!gap[dep[u]])return ans; dep[u] = Min+1; gap[dep[u]]++; if(u != start) u = edge[pre[u]^1].to; } return ans;}int main(){ int T, cas=1, n, m, a, b, c, d; s(T); while(T--) { init(); s(n), s(m); for(int i=0; i<m; ++i) { s(a), s(b), s(c), s(d); add(a, b, (LL)c*(m+1)+1); if(d) add(b, a, (LL)c*(m+1)+1); } printf("Case %d: %lld\n",cas++, SAP(0, n-1, n)%(m+1)); } return 0;}
阅读全文
0 0
- HDU3987:Harry Potter and the Forbidden Forest(最小割边数)
- hdu3987 Harry Potter and the Forbidden Forest 最小割边数
- HDU3987 Harry Potter and the Forbidden Forest(最小割)
- hdu3987 Harry Potter and the Forbidden Forest 最小割割边最少
- HDU3987 Harry Potter and the Forbidden Forest最小割最少边Dinic
- HDU 3987 Harry Potter and the Forbidden Forest(最小割的最少割边数)
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- 【HDU】3987 Harry Potter and the Forbidden Forest 最小割
- 【最小割】HDU 3987 Harry Potter and the Forbidden Forest
- hdu 3987 Harry Potter and the Forbidden Forest 最小割
- HDU 3987 Harry Potter and the Forbidden Forest(最小割中的最少割边)经典
- hdu 3987 Harry Potter and the Forbidden Forest (最小割)
- 多校15场WHU Harry Potter and the Forbidden Forest(求网络的最小割的最小边数)
- HDU--3987[Harry Potter and the Forbidden Forest] 求最小割集中的最小边数
- Harry Potter and the Forbidden Forest(割边最小的最小割)
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
- HDU 3987 Harry Potter and the Forbidden Forest (求割边最少的最小割)
- HDOJ 3987 - Harry Potter and the Forbidden Forest 设置偏移量,最小割
- Spring Cloud初探——服务治理Spring Cloud Eureka
- 不区分字母大小写排序
- 豆瓣社区:《如何高效学习》应用与心得
- Echarts绘制折线图柱状图混合图表练习
- java中的对象游离
- HDU3987:Harry Potter and the Forbidden Forest(最小割边数)
- 彻底卸载Python及安装的Python模块
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- php 常驻后台
- Json数据解析
- uboot基础知识
- Oracle SQL性能优化
- 跨域
- 【单调栈 or 分治】51Nod1215[数组的宽度]题解