Travel
"Problem description"
The town of Z is a pleasant place to visit, attracting tourists from all over the world. There are N attractions near small town (numbered,..., N), which are connected by M-Road, all roads are bidirectional, and there may be many roads between the two attractions. Perhaps to protect the tourist resources of the land, Z town has a strange rule that for a given road RI, any vehicle on that road must be at a speed of VI.
Speed changes are so fast that visitors are uncomfortable, so when you go from one spot to another, you want to choose the route that is as small as possible for the maximum speed and minimum speed in the process, the so-called most comfortable route.
"Input File"
The first line contains two positive integers, N and M.
The next M-line contains three positive integers per line: x, Y, and V. Indicates that there is a two-way road between the sights X and the attraction Y, and the vehicle must travel at speed v on the public road.
The last line contains two positive integer s,t, indicating the shortest path from attraction s to the maximum minimum speed of attraction T. S and T cannot be the same.
"Output File"
If the attraction s to attractions t have no path, output "impossible". Otherwise the output is a number that represents the minimum speed ratio. If necessary, output an approximate fraction.
"Sample input and Output"
"Sample input
1
"
4 2
1 2 1
3 4 2
1 4
"Sample input
2
"
3 3
1 2 10
1 2 5
2 3 8
1 3
"Sample input
3
"
3 2
1 2 2
2 3 4
1 3
"Sample output
1
"
Impossible
"Sample output
2
"
5/4
"Sample output
3
"
2
"Data range"
For 100% of data, 1<n≤500,1≤x,y≤n,0<v<30000,x≠y,0<m≤5000
Very good question ...
There are two main ways of thinking:
1. minimum spanning tree;
We enumerate each edge, assuming it is the smallest edge, so it is less than its edge all deleted, make a minimum spanning tree, easy to draw the ratio of the minimum and maximum edge;
2.SPFA;
The idea is similar to the first one, which simultaneously needs to enumerate each edge, Spfa[i], to the value of the largest edge of the node to I;
Then according to SPFA, as far as possible not to update the largest edge can;
The code is not very complete, first dig a hole to put the good;
Because is a good question, first said the next thought;
Travel [SPFA or minimum spanning tree] [flexible problem of simple algorithm]