• HDU 3691 Nubulsa Expo(全局最小割)


    Problem Description
    You may not hear about Nubulsa, an island country on the Pacific Ocean. Nubulsa is an undeveloped country and it is threatened by the rising of sea level. Scientists predict that Nubulsa will disappear by the year of 2012. Nubulsa government wants to host the 2011 Expo in their country so that even in the future, all the people in the world will remember that there was a country named “Nubulsa”.
    As you know, the Expo garden is made up of many museums of different countries. In the Expo garden, there are a lot of bi-directional roads connecting those museums, and all museums are directly or indirectly connected with others. Each road has a tourist capacity which means the maximum number of people who can pass the road per second.
    Because Nubulsa is not a rich country and the ticket checking machine is very expensive, the government decides that there must be only one entrance and one exit. The president has already chosen a museum as the entrance of the whole Expo garden, and it’s the Expo chief directory Wuzula’s job to choose a museum as the exit.
    Wuzula has been to the Shanghai Expo, and he was frightened by the tremendous “people mountain people sea” there. He wants to control the number of people in his Expo garden. So Wuzula wants to find a suitable museum as the exit so that the “max tourists flow” of the Expo garden is the minimum. If the “max tourist flow” is W, it means that when the Expo garden comes to “stable status”, the number of tourists who enter the entrance per second is at most W. When the Expo garden is in “stable status”, it means that the number of people in the Expo garden remains unchanged.
    Because there are only some posters in every museum, so Wuzula assume that all tourists just keep walking and even when they come to a museum, they just walk through, never stay.

    Input
    There are several test cases, and the input ends with a line of “0 0 0”.

    For each test case:
    The first line contains three integers N, M and S, representing the number of the museums, the number of roads and the No. of the museum which is chosen as the entrance (all museums are numbered from 1 to N). For example, 5 5 1 means that there are 5 museums and 5 roads connecting them, and the No. 1 museum is the entrance.
    The next M lines describe the roads. Each line contains three integers X, Y and K, representing the road connects museum X with museum Y directly and its tourist capacity is K.

    Please note:
    1<N<=300, 0<M<=50000, 0<S,X,Y<=N, 0<K<=1000000

    Output
    For each test case, print a line with only an integer W, representing the “max tourist flow” of the Expo garden if Wuzula makes the right choice.

    Sample Input
    5 5 1
    1 2 5
    2 4 6
    1 3 7
    3 4 3
    5 1 10
    0 0 0

    Sample Output
    8

    题意

    N个博物馆,M条路,S为入口,要求你找个出口T,使得从S-T的人流量总和最小,就是S-T的最大流最小,输出最大流

    题解

    由于最大流=最小割,根据全局最小割可知,两个集合a和b,无论S在哪个集合,都有另1个集合的点满足,所以S根本不用考虑

    所以题目就变成求全局最小割

    代码

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 const int maxn=305;
     5 const int INF=0x3f3f3f3f;
     6 
     7 int G[maxn][maxn],wage[maxn],v[maxn];
     8 bool vis[maxn],in[maxn];
     9 int n,m;
    10 
    11 int Stoer_wagner()
    12 {
    13     int ans=INF;
    14     for(int i=1;i<=n;i++)v[i]=i;
    15     while(n>1)
    16     {
    17         memset(vis,0,sizeof vis);
    18         memset(wage,0,sizeof wage);
    19         int k,pre=1;
    20         vis[v[pre]]=true;
    21         for(int i=1;i<=n;i++)
    22         {
    23             k=-1;
    24             for(int j=1;j<=n;j++)
    25                 if(!vis[v[j]])
    26                 {
    27                     wage[v[j]]+=G[v[pre]][v[j]];
    28                     if(k==-1||wage[v[k]]<wage[v[j]])k=j;
    29                 }
    30             vis[v[k]]=true;
    31             if(i==n-1)
    32             {
    33                 ans=min(ans,wage[v[k]]);
    34                 if(ans==0)return ans;
    35                 for(int j=1;j<=n;j++)
    36                 {
    37                     G[v[pre]][v[j]]+=G[v[j]][v[k]];
    38                     G[v[j]][v[pre]]+=G[v[j]][v[k]];
    39                 }
    40                 v[k]=v[n--];
    41             }
    42             pre=k;
    43         }
    44     }
    45     return ans;
    46 }
    47 int main()
    48 {
    49     while(scanf("%d%d%*d",&n,&m)!=EOF,n||m)
    50     {
    51         memset(G,0,sizeof G);
    52         for(int i=0,u,v,w;i<m;i++)
    53         {
    54             scanf("%d%d%d",&u,&v,&w);
    55             G[u][v]+=w;
    56             G[v][u]+=w;
    57         }
    58         printf("%d
    ",Stoer_wagner());
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    bzoj 4010: [HNOI2015]菜肴制作
    bzoj4827: [Hnoi2017]礼物
    bzoj3160: 万径人踪灭
    bzoj4503: 两个串
    bzoj2648: SJY摆棋子
    bzoj2780: [Spoj]8093 Sevenk Love Oimaster
    bzoj3926: [Zjoi2015]诸神眷顾的幻想乡
    MySQL:记录的增删改查、单表查询、约束条件、多表查询、连表、子查询、pymysql模块、MySQL内置功能
    MySQL数据库:SQL语句基础、库操作、表操作、数据类型、约束条件、表之间的关系
    网络编程进阶:并发编程之协程、IO模型
  • 原文地址:https://www.cnblogs.com/taozi1115402474/p/9604924.html
Copyright © 2020-2023  润新知