[SOJ] Guide

Source: Internet
Author: User

Description

Mr. G. Works for a travel company in Bangladesh. His current task is to take some tourists to some distant cities. Like all countries, there are two-way roads between some cities. There is a bus route between each pair of neighboring cities, and each route has its own maximum number of passengers. There is a map containing road conditions between cities and the maximum capacity of buses.
It is often impossible to take all passengers to their destination at once. For example, in the map of the 7 cities below, the side represents the road, and the number on each edge represents the maximum capacity of the bus on the road.

If Mr. G. To bring 99 passengers from the City 1 to the City 7, it is necessary to return at least 5 times (he must accompany each group of passengers). The best route is 1-2-4-7.

Initial: 1 (99) 2 (0) 4 (0) 7 (0)

1th round-Trip: 1 (75) 2 (0) 4 (0) 7 (24)

2nd round-Trip: 1 (51) 2 (0) 4 (0) 7 (48)

3rd round-Trip: 1 (27) 2 (0) 4 (0) 7 (72)

4th round-Trip: 1 (3) 2 (0) 4 (0) 7 (96)

5th round-Trip: 1 (0) 2 (0) 4 (0) 7 (99)

Input

The first behavior is an integer t, which indicates the number of test cases. The first row of each set of data has two integers N (n≤100) and R (r≤4950), respectively, representing the number of cities and the number of roads. The next R line has 3 integers (c1,c2,p) per line, where C1 and C2 are the city numbers, and P (1<p<10000) is the maximum capacity of the bus on that road. Successive integers numbered 1~n in each city. Line r+1 contains 3 integers (s,d,t) representing the departure city, the number of the destination city, and the number of visitors (1<t<100000). Ensure that there is a maximum of one road between two cities.

Output

For each set of input data, the minimum number of round trips is output.

Sample input Copy sample input to Clipboard
17 101 2 301 3 151 4 102 4 252 5 603 4 403 6 204 7 355 7 206 7 301 7 99
Sample Output
5

#include <iostream> #include <algorithm>using namespace std;const int MAX = 105;const int INF = -1;int N, r;int E Dge[max][max];void Init () {for  (int. i=0;i<n;i++)  {for    (int j=0;j<n;j++)      edge[i][j]=inf;    edge[i][i]=0;}  } int main () {  int t;  cin>>t;  while (t--)  {    cin>>n>>r;    int A, b, X;    Init ();    for (int i=0;i<r;i++)    {      cin>>a>>b>>x;      edge[a][b]=x;      edge[b][a]=x;    }      for (int k=1;k<=n;k++) for (int      i=1;i<=n;i++) for        (int j=1;j<=n;j++)        {           Edge[i][j]=max ( Edge[i][j],min (Edge[i][k], edge[k][j]));        }    int S, E, p;    cin>>s>>e>>p;    cout<<p/(edge[s][e]-1) + (p%edge[s][e]?1:0) <<endl;  }  return 0;}

  

[SOJ] Guide

Related Article

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.