【2017 ACM/ICPC Asia Regional Qingdao Online 1009】hdu 6214 Smallest Minimum Cut
来源:互联网 发布:python mat函数 编辑:程序博客网 时间:2024/06/07 06:48
Smallest Minimum Cut
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 269 Accepted Submission(s): 76
Total Submission(s): 269 Accepted Submission(s): 76
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
题意:
求最小割边数,模板题
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;const __int64 inf = 10000000000000LL;const int maxn = 100010;int head[maxn], tol, dep[maxn], n;struct node{ int from, to, next; __int64 cap;} edge[1000000];void add(int u, int v, __int64 cap){ edge[tol] = (node) { u, v, head[u], cap }; head[u] = tol++; edge[tol] = (node) { v, u, head[v], 0 }; head[v] = tol++;}int bfs(int s, int t){ int que[maxn], front = 0, rear = 0; memset(dep, -1, sizeof(dep)); dep[s] = 0; que[rear++] = s; while (front != rear) { int u = que[front++]; front %= maxn; for (int i = head[u]; i != -1; i = edge[i].next) { int v = edge[i].to; if (edge[i].cap > 0 && dep[v] == -1) { dep[v] = dep[u] + 1; que[rear++] = v; rear %= maxn; if (v == t) { return 1; } } } } return 0;}__int64 dinic(int s, int t){ __int64 res = 0; while (bfs(s, t)) { int Stack[maxn], top, cur[maxn]; memcpy(cur, head, sizeof(head)); top = 0; int u = s; while (1) { if (t == u) { __int64 min = inf; int loc; for (int i = 0; i < top; i++) if (min > edge[Stack[i]].cap) { min = edge[Stack[i]].cap; loc = i; } for (int i = 0; i < top; i++) { edge[Stack[i]].cap -= min; edge[Stack[i] ^ 1].cap += min; } res += min; top = loc; u = edge[Stack[top]].from; } for (int i = cur[u]; i != -1; cur[u] = i = edge[i].next) if (dep[edge[i].to] == dep[u] + 1 && edge[i].cap > 0) { break; } if (cur[u] != -1) { Stack[top++] = cur[u]; u = edge[cur[u]].to; } else { if (top == 0) { break; } dep[u] = -1; u = edge[Stack[--top]].from; } } } return res;}int main(){ int i, j, m, T, s, t; __int64 k; scanf("%d", &T); while (T--) { scanf("%d%d", &n, &m); scanf("%d%d", &s, &t); memset(head, -1, sizeof(head)); tol = 0; while (m--) { scanf("%d%d%I64d", &i, &j, &k); add(i, j, k * 200001 + 1); //add(j, i, k * 200001 + 1); add(j, i, 0); } __int64 ans = dinic(s, t); cout << ans % 200001 << endl; } return 0;}
阅读全文
0 0
- 【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 HDU 6214 Smallest Minimum Cut(最小割的边数)
- 2017 ACM/ICPC Asia Regional Qingdao Online Smallest Minimum Cut 网络流
- HDU6214 Smallest Minimum Cut 最小割/最少边 [2017 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
- HDU 5879 Cure 2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5884 Sort 2016 ACM/ICPC Asia Regional Qingdao Online
- HDU 5878 -- 丑数打表(2016 ACM/ICPC Asia Regional Qingdao Online)
- HDU 5878 -- 丑数打表(2016 ACM/ICPC Asia Regional Qingdao Online)
- 【2016 ACM/ICPC Asia Regional Qingdao Online】
- 2016 ACM/ICPC Asia Regional Qingdao Online
- 编译原理(2):文法和语言
- test2
- 梦幻古龙2.058商业端一键安装
- Hbase数据存储图解与数据检索流程
- 模糊查询和排序
- 【2017 ACM/ICPC Asia Regional Qingdao Online 1009】hdu 6214 Smallest Minimum Cut
- go语言包管理
- POJ
- XLView内镶嵌viewpager无限轮播 AND 多条目
- 频道管理+popuwindow
- Javascript实现HashMap
- 求正整数的二进制表示中最低位1的位置
- 特征工程(1)
- 神迹单机一键端全套