UVa10099_The Tourist Guide (Shortest Path/floyd), uva10099_thefloyd

Source: Internet
Author: User

UVa10099_The Tourist Guide (Shortest Path/floyd), uva10099_thefloyd

Solution report

Question:

A tour group now has n cities and m roads. Since the maximum number of people allowed to pass is specified on each road, I would like to ask if the number of people in this tour group is known and at least a few trips need to be shipped.

Ideas:

Find the path from the starting point to the ending point, where the minimum value is the maximum.

There may be many ways to solve the issue. The shortest-Shortest method is one, and the shortest-tree method is also one (ps, prime and dijs are subclasses like this)

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#define inf 0x3f3f3f3fusing namespace std;int n,m,q,mmap[110][110];void floyd() {    for(int k=0; k<n; k++)        for(int i=0; i<n; i++)            for(int j=0; j<n; j++)                mmap[i][j]=max(mmap[i][j],min(mmap[i][k],mmap[k][j]));}int main() {    int i,j,u,v,w,k=1;    while(~scanf("%d%d",&n,&m)) {        if(!n&&!m)break;        for(i=0; i<n; i++) {            for(j=0; j<n; j++)                mmap[i][j]=0;        }        for(i=0; i<m; i++) {            scanf("%d%d%d",&u,&v,&w);            mmap[u-1][v-1]=mmap[v-1][u-1]=w;        }        floyd();        scanf("%d%d%d",&u,&v,&w);        int ans=0,num=mmap[u-1][v-1]-1;        ans=ceil((double)w/num);        printf("Scenario #%d\n",k++);        printf("Minimum Number of Trips = %d\n\n",ans);    }    return 0;}

The Tourist Guide

Input:Standard input

Output:Standard output

 

Mr. g. works as a tourist guide. his current assignment is to take some tourists from one city to another. some two-way roads connect the cities. for each pair of neighboring cities there is a bus service that runs only between those two cities and uses the road that directly connects them. each bus service has a limit on the maximum number of passengers it can carry. mr. g. has a map showing the cities and the roads connecting them. he also has the information regarding each bus service. he understands that it may not always be possible for him to take all the tourists to the destination city in a single trip. for example, consider the following road map of 7 cities. the edges connecting the cities represent the roads and the number written on each edge indicates the passenger limit of the bus service that runs on that road.

 

Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips, since he has to ride the bus with each group, and the route he shocould take is: 1-2-4-7.

But, Mr. g. finds it difficult to find the best route all by himself so that he may be able to take all the tourists to the destination city in minimum number of trips. so, he seeks your help.

 

Input

The input will contain one or more test cases. The first line of each test case will contain two integers:N(N <= 100) andRRepresenting respectively the number of cities and the number of road segments. ThenRLines will follow each containing three integers:C1,C2AndP.C1 andC2Are the city numbers andP(P> 1) is the limit on the maximum number of passengers to be carried by the bus service between the two cities. City numbers are positive integers ranging from 1N. (R+ 1)-th line will contain three integers:S,DAndTRepresenting respectively the starting city, the destination city and the number of tourists to be guided.

The input will end with two zeroesNAndR.

 

Output

For each test case in the input first output the scenario number. then output the minimum number of trips required for this case on a separate line. print a blank line after the output of each test case.

 

Sample Input

7 10
1 2 30
1 3 15
1 4 10
2 4 25
2 5 60
3 4 40
3 6 20
4 7 35
5 7 20
6 7 30
1 7 99
0 0

Sample Output

Scenario #1
Minimum Number of Trips = 5



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.