zoukankan      html  css  js  c++  java
  • HDU 6214 Smallest Minimum Cut(最少边最小割)

    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 network G, 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 integers s and t (1≤s,t≤n) corresponding to the source and sink.
    Each of the next m lines contains three integers u,v and w (1≤w≤255) describing a directed edge from node u to v with capacity w.

    Output
    For each test case, output the smallest size of all minimum cuts in a line.

    Sample Input
    2
    4 5
    1 4
    1 2 3
    1 3 1
    2 3 1
    2 4 1
    3 4 2
    4 5
    1 4
    1 2 3
    1 3 1
    2 3 1
    2 4 1
    3 4 3

    Sample Output
    2
    3

    题意

    给你一个网络图,求最少边最小割

    题解

    如果流量全为1的话很容易知道最小边最小割=最小割

    如果流量不为1,我们肯定要让哪里为1才可以得到答案

    可以对边的权值进行hash,w-->w*hash+1

    再跑最小割,跑完的答案%hash即可,这里hash>m就行

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn=1e5+5;
     5 const int maxm=2e5+5;
     6 int n,m,S,T;
     7 int deep[maxn],q[400000];
     8 int FIR[maxn],TO[maxm],CAP[maxm],COST[maxm],NEXT[maxm],tote;
     9 
    10 void add(int u,int v,int cap)
    11 {
    12     TO[tote]=v;
    13     CAP[tote]=cap;
    14     NEXT[tote]=FIR[u];
    15     FIR[u]=tote++;
    16 
    17     TO[tote]=u;
    18     CAP[tote]=0;
    19     NEXT[tote]=FIR[v];
    20     FIR[v]=tote++;
    21 }
    22 bool bfs()
    23 {
    24     memset(deep,0,sizeof deep);
    25     deep[S]=1;q[1]=S;
    26     int head=0,tail=1;
    27     while(head!=tail)
    28     {
    29         int u=q[++head];
    30         for(int v=FIR[u];v!=-1;v=NEXT[v])
    31         {
    32             if(CAP[v]&&!deep[TO[v]])
    33             {
    34                 deep[TO[v]]=deep[u]+1;
    35                 q[++tail]=TO[v];
    36             }
    37         }
    38     }
    39     return deep[T];
    40 }
    41 int dfs(int u,int fl)
    42 {
    43     if(u==T)return fl;
    44     int f=0;
    45     for(int v=FIR[u];v!=-1&&fl;v=NEXT[v])
    46     {
    47         if(CAP[v]&&deep[TO[v]]==deep[u]+1)
    48         {
    49             int Min=dfs(TO[v],min(fl,CAP[v]));
    50             CAP[v]-=Min;CAP[v^1]+=Min;
    51             fl-=Min;f+=Min;
    52         }
    53     }
    54     if(!f)deep[u]=-2;
    55     return f;
    56 }
    57 int maxflow()
    58 {
    59     int ans=0;
    60     while(bfs())
    61         ans+=dfs(S,1<<30);
    62     return ans;
    63 }
    64 void init()
    65 {
    66     tote=0;
    67     memset(FIR,-1,sizeof FIR);
    68 }
    69 int main()
    70 {
    71     int _;
    72     cin>>_;
    73     while(_--)
    74     {
    75         init();
    76         cin>>n>>m>>S>>T;
    77         for(int i=0,u,v,w;i<m;i++)
    78         {
    79             cin>>u>>v>>w;
    80             add(u,v,w*1001+1);
    81         }
    82         printf("%d
    ",maxflow()%1001);
    83     }
    84     return 0;
    85 }
  • 相关阅读:
    手写简易SpringMVC框架,包含@PathVariable
    高并发下,如何保证接口的幂等性?
    JAVA判断奇偶数
    多线程ForkJoin-分治思想
    websocket简单使用
    Git使用教程:最详细、最傻瓜、最浅显、真正手把手教!(转载学习)
    linux配置java环境变量(详细)
    java缓存技术的介绍(转载)
    java 多态性详解及常见面试题
    oracle数据库基础知识总结(一)
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9545150.html
Copyright © 2011-2022 走看看