ayit第十三周训练的c题

Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.

Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4
#include<stdio.h>
#include<string.h>
int e[1100][1100],b1[1010],d1[1010];
int t;
int min(int a,int b)
{
    if(a>b)
        return b;
    return a;
}
int main()
{
    int x;
    int m,n,t1,t2,t3,i,j,s,s1,max;
    while(~scanf("%d",&t))
    {
        x=0;
        while(t--)
        {
            x++;
            memset(e,0,sizeof(e));
            memset(b1,0,sizeof(b1));
            scanf("%d %d",&n,&m);
            for(i=1; i<=m; i++)
            {
                scanf("%d %d %d",&t1,&t2,&t3);
                if(e[t1][t2]<t3)
                {
                    e[t1][t2]=t3;
                    e[t2][t1]=t3;
                }
            }
            for(i=1; i<=n; i++)
            {
                d1[i]=e[1][i];
            }
            b1[1]=1;
            for(i=1; i<n; i++)
            {
                max=-1;
                for(j=1; j<=n; j++)
                {
                    if(b1[j]==0&&d1[j]>max)
                    {
                        max=d1[j];
                        s1 = j;
                    }
                }
                b1[s1]=1;
                for(s=1; s<=n; s++)
                {
                    if(d1[s]<min(d1[s1],e[s1][s]))
                    {
                        d1[s]=min(d1[s1],e[s1][s]);
                    }
                }
            }
            printf("Scenario #%d:\n",x);
            printf("%d\n\n",d1[n]);
        }
    }

    return 0;
}

翻译   雨果重工很高兴。Cargolifter项目崩溃后,他现在可以扩展业务。但是他需要一个聪明的人,告诉他从客户建造巨型钢起重机的地方到所有街道都可以承载重量的地方是否真的有办法。
幸运的是,他已经制定了一个计划,包括所有街道和桥梁以及所有允许的重量。不幸的是,他不知道如何找到最大重量来告诉他的客户起重机可能会变得很重。但是你当然知道。
问题
系统会为您提供城市规划,由交叉口之间的街道(权重限制)描述,该街道编号为1到n。您的任务是找到从1号交叉口(Hugo的位置)到n号交叉口(客户的位置)可以运输的最大重量。您可以假设至少有一条路径。所有街道均可双向行驶。

输入   

第一行包含方案(城市计划)的数量。对于每个城市,第一行给出的是路口交叉口数量n(1 <= n <= 1000)和街道数量m。接下来的m行包含整数的三元组,这些整数指定了道路的起点和终点交叉点以及允许的最大权重,该权重为正且不大于1000000。每对交叉点之间最多有一条街道。

输出

每个方案的输出都以包含“方案#i:”的行开头,其中i是从1开始的方案编号。然后打印一行,其中包含Hugo可以运输给客户的最大允许重量。用空白行终止方案的输出。

题意   :每条路上可以搭载的货物量有上限,问要走到终点,可以运载的最大载物量

思路   寻找每条可能行的通的路中,最小的那条边,再把每条路中最小的这条边中取最大的值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值