hdu 6214 Smallest Minimum Cut[最大流]

Posted GraceSkyer

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 6214 Smallest Minimum Cut[最大流]相关的知识,希望对你有一定的参考价值。

hdu 6214 Smallest Minimum Cut[最大流]

题意:求最小割中最少的边数。

题解:对边权乘个比边大点的数比如300,再加1 ,最后,最大流对300取余就是边数啦。。

技术分享
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<vector>
 7 #include<queue>
 8 using namespace std;
 9 #define CLR(a,b) memset((a),(b),sizeof((a)))
10 typedef long long ll;
11 const int N = 205;
12 const int inf = 0x3f3f3f3f;
13 int n, m, S, T;
14 int dep[N], cur[N];
15 int head[N];
16 struct Edge{
17     int v, c, nex;
18     Edge(int _v=0,int _c=0,int _nex=0):v(_v),c(_c),nex(_nex){}
19 };
20 vector<Edge>E;
21 void add(int u,int v,int c){E.push_back(Edge(v,c,head[u]));head[u]=E.size()-1;}
22 
23 bool bfs() {
24     queue<int> q;
25     CLR(dep, -1);
26     q.push(S); dep[S] = 0;
27     while(!q.empty()) {
28         int u = q.front(); q.pop();
29         for(int i = head[u]; ~i; i = E[i].nex) {
30             int v = E[i].v;
31             if(E[i].c && dep[v] == -1) {
32                 dep[v] = dep[u] + 1;
33                 q.push(v);
34             }
35         }
36     }
37     return dep[T] != -1;
38 }
39 int dfs(int u, int flow) {
40     if(u == T) return flow;
41     int w, used=0;
42     for(int i = head[u]; ~i; i = E[i].nex) {
43         int v = E[i].v;
44         if(dep[v] == dep[u] + 1) {
45             w = flow - used;
46             w = dfs(v, min(w, E[i].c));
47             E[i].c -= w;  E[i^1].c += w;
48             if(v) cur[u] = i;
49             used += w;
50             if(used == flow) return flow;
51         }
52     }
53     if(!used) dep[u] = -1;
54     return used;
55 }
56 int dinic() {
57     int ans = 0;
58     while(bfs()) {
59         for(int i = 1; i <= T;i++)
60             cur[i] = head[i];
61         ans += dfs(S, inf);
62     }
63     return ans;
64 }
65 int main() {
66     int t, i, u, v, w;
67     scanf("%d", &t);
68     while(t--) {
69         E.clear(); CLR(head, -1);
70         scanf("%d%d", &n, &m);
71         scanf("%d%d", &S, &T);
72         for(i = 1; i <= m; ++i) {
73             scanf("%d%d%d", &u, &v, &w);
74             add(u, v, w*300+1); add(v, u, 0);
75         }
76         int ans = dinic()%300;
77         printf("%d\n", ans);
78     }
79     return 0;
80 }
249ms

 

以上是关于hdu 6214 Smallest Minimum Cut[最大流]的主要内容,如果未能解决你的问题,请参考以下文章

HDU 6214 Smallest Minimum Cut 最小割,权值编码

HDU 6214 最小割边

hdu 6214

HDU 6214最少的最小割边数

2017青岛赛区网络赛 Smallest Minimum Cut 求最小割的最小割边数

Leetcode 1509. Minimum Difference Between Largest and Smallest Value in Three Moves