• 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
    ", ans);
    78     }
    79     return 0;
    80 }
    249ms
  • 相关阅读:
    如何启用apache的gzip压缩?
    Zend Framework配置Nginx的rewrite
    数据库差异比较工具
    心愿王泽 杨颖 乔媛 唐景莲
    在所有存储过程中查找一个关键字
    通用分页存储过程
    JavaScript开发工具 Aptana
    js如何控制select控件(下拉列表)
    Read and write flat file
    Extreme Programming
  • 原文地址:https://www.cnblogs.com/GraceSkyer/p/7536797.html
Copyright © 2020-2023  润新知