UVALive 5099 Nubulsa Expo 全局最小割问题

本文探讨了Nubulsa政府如何通过选择合适的出口博物馆来最小化其博览会的最大游客流量,确保稳定状态下的游客数量保持不变,从而实现可持续发展。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B - Nubulsa Expo
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Description

Download as PDF

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$ \le$300, 0 < M$ \le$50000, 0 < S, X, Y$ \le$N, 0 < K$ \le$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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 555
#define inf 1<<30

int v[MAXN],dist[MAXN];
int map[MAXN][MAXN];
bool vis[MAXN];
int n,m;

//求全局最小割的Stoer_Wanger算法
 int Stoer_Wanger(int n)
{
     int res=inf;
    for(int i=0;i<n;i++)v[i]=i;
    while(n>1){
        int k=0,pre=0;//pre用来表示之前加入A集合的点,我们每次都以0点为第一个加入A集合的点
        memset(vis,false,sizeof(vis));
        memset(dist,0,sizeof(dist));
        for(int i=1;i<n;i++){
            k=-1;
            for(int j=1;j<n;j++){
                if(!vis[v[j]]){
                    dist[v[j]]+=map[v[pre]][v[j]];//dis数组用来表示该点与A集合中所有点之间的边的长度之和
                    if(k==-1||dist[v[k]]<dist[v[j]]){
                        k=j;
                    }
                }
            }
            vis[v[k]]=true;
            if(i==n-1){
                res=min(res,dist[v[k]]);
                //将该点合并到pre上,相应的边权就要合并
                for(int j=0;j<n;j++){
                    map[v[pre]][v[j]]+=map[v[j]][v[k]];
                    map[v[j]][v[pre]]+=map[v[j]][v[k]];
                }
                v[k]=v[--n];//删除最后一个点
            }
            pre=k;
        }
    }
    return res;
}

int main()
{
    int u,v,w,ss;
    while(~scanf("%d%d",&n,&m)){

        memset(map,0,sizeof(map));
        while(m--){
            scanf("%d%d%d",&u,&v,&w);
           u--,v--;
            map[u][v]+=w;
            map[v][u]+=w;
        }
        int ans=Stoer_Wanger(n);
        printf("%d\n",ans);
    }
    return 0;
}

 


转载于:https://www.cnblogs.com/13224ACMer/p/4726259.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值