老BOJ 12 Heavy Cargo

Heavy Cargo
Accept:85    Submit:228
Time Limit:1000MS    Memory Limit:65536KB

Description
Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their latest model, the Godzilla V12, is so big that the amount of cargo you can transport with it is never limited by the truck itself. It is only limited by the weight restrictions that apply for the roads along the path you want to drive.

Given start and destination city, your job is to determine the maximum load of the Godzilla V12 so that there still exists a path between the two specified cities.


Input
The input will contain one or more test cases. The first line of each test case will contain two integers: the number of cities n (2<=n<=200) and the number of road segments r (1<=r<=19900) making up the street network.
Then r lines will follow, each one describing one road segment by naming the two cities connected by the segment and giving the weight limit for trucks that use this segment. Names are not longer than 30 characters and do not contain white-space characters. Weight limits are integers in the range 0 - 10000. Roads can always be travelled in both directions.
The last line of the test case contains two city names: start and destination.
Input will be terminated by two values of 0 for n and r.


Output
For each test case, print three lines:

  • a line saying "Scenario #x" where x is the number of the test case

  • a line saying "y tons" where y is the maximum possible load

a blank line

Sample Input

4 3

Karlsruhe Stuttgart 100

Stuttgart Ulm 80

Ulm Muenchen 120

Karlsruhe Muenchen

5 5

Karlsruhe Stuttgart 100

Stuttgart Ulm 80

Ulm Muenchen 120

Karlsruhe Hamburg 220

Hamburg Muenchen 170

Muenchen Karlsruhe

0 0

Sample Output

Scenario #1

80 tons


Scenario #2

170 tons


Floyd or Dijkstra遍历无向图,求出所有连通分量中权重最小的一条边

#include <iostream>
using namespace std;
char name[201][50];
int w[201][201],dis[201];
int sum,n,r;
int getnum(char t[])
{
    for(int i=0; i<=sum; i++)
        if(!strcmp(name[i], t))
            return i;
    sum++;
    strcpy(name[sum], t);
    return sum;
}
int Dijkstra(int s, int e)
{
    int i,j,t,minw;
    bool flag[201]= {0};
    for(i=0; i<n; i++)
        dis[i] = w[s][i];
    dis[s]=0;
    flag[s]=true;
    for(i=0; i<n; i++)
    {
        minw = dis[e];
        t = s;
        for(j=0; j<n; j++)
            if(dis[j]>minw && !flag[j])
            {
                t = j;
                minw = dis[j];
            }
        if(flag[t]) return dis[e];
        flag[t] = true;
        for(j=0; j<n; j++)
            if(!flag[j] && w[t][j]>-1)
            {
                minw = dis[t]>w[t][j]?w[t][j]:dis[t];
                dis[j] = dis[j]<minw?minw:dis[j];
            }
    }
    return dis[e];
}
int main()
{
    int i,weight,s,e,Case=0;
    char a[50],b[50];
    while(scanf("%d %d%*c", &n, &r),n+r)
    {
        memset(w,-1,sizeof(w));
        memset(name,'\0',sizeof(name));
        sum=-1;
        for(i=0; i<r; i++)
        {
            scanf("%s %s %d", &a, &b, &weight);
            s = getnum(a);
            e = getnum(b);
            w[s][e]=w[e][s]=weight;
        }
        scanf("%s %s", &a, &b);
        s = getnum(a);
        e = getnum(b);
        printf("Scenario #%d\n%d tons\n\n",++Case, Dijkstra(s,e));
    }
    return 0;
}


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值