The most comfortable route--the sixth annual College student Program design competition in Henan province

Source: Internet
Author: User

Title Description

The irregular eggs lurk in a neural network in a region. Its network is a total of n neurons (numbered ,..., n), which are connected by M- channel. There may be multiple channels between two neurons. irregular eggs can swim back and forth on these channels, but the speed of any channel in the neural network must be certain. Of course , irregular eggs do not want to swim from one channel to another, the speed of change is too large, otherwise it will be very uncomfortable.

Now the alien eggs inhabit the neuron S Point and want to swim to the neuron T point. It wants to choose the route with the greatest speed and minimum speed in a swimming process, which is the so-called most comfortable route.

Input

First line: K indicates how many sets of test data are available.

Next to each set of test data:

Line 1 : N M

2~m+1 xi  yi  vi   (i=1, ..,m)

means neuron x i yi vi

Last line: s T (s ¹ t)

2≤K≤5   1 <n≤ 5 00   0<m5000   ≤xi, Yi, S, T ≤n    0< <30000

VI is an integer. There is a space between the data.

Output

For each set of test data, output one line: if the neuron S to Neuron T has no route, the output is "impossible". Otherwise the output is a number that represents the minimum speed ratio. If necessary, output an approximate fraction.

Sample input
23 21 2 22 3 41 33 31 2 101 2 52 3 81 3
Sample output
25/4
Hint Source

The sixth annual College student Program design competition in Henan province

Idea: Enumerate the most speed of the edge, a strip of the speed is smaller than its edge, until the two places connected-here you can use and check set, compare ratios, take the smallest on the line.

#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#defineINF 0XFFFFFFF#defineN 5500using namespacestd;intF[n];structnode{intx,y,v;};intCMP (node A,node b) {returna.v<B.V;}intgcdintMintN) {    returnN?GCD (n,m%N): M;}intFind (intx) {    returnx==f[x]?x:f[x]=Find (f[x]);}intMain () {intN,P,Q,T,M,I,J,MINV,MAXV;    Node A[n]; scanf ("%d",&T);  while(t--) {memset (A,0,sizeof(a)); scanf ("%d%d",&n,&m);  for(i=1; i<=m;i++) {scanf (" %d%d%d",&a[i].x,&a[i].y,&a[i].v); } scanf ("%d%d",&p,&q); Sort (a+1, a+m+1, CMP); Doubleans=INF;  for(i=m;i>=1; i--)//start with the largest side and add the smaller side        {             for(j=1; j<=n;j++) F[j]=K;  for(j=i;j>0; j--)            {                intx=Find (a[j].x); inty=Find (A[J].Y); if(x!=y) {f[x]=y; }                Else                    Continue ; if(Find (P) ==find (q))//the starting and ending points are in a collection.                     Break; }            if(j==0)//If you add all the edges, it means that the start and end are not connected.                 Break; if(a[i].v*1.0/a[j].v<ans) {ans=a[i].v*1.0/a[j].v; MAXV=a[i].v; MINV=a[j].v; }        }        if(ans==INF) printf ("impossible\n"); Else if(maxv%minv==0) printf ("%d\n", maxv/MINV); Elseprintf ("%d/%d\n", MAXV/GCD (MAXV,MINV), minv/gcd (MAXV,MINV)); }    return 0;}

The most comfortable route--the sixth annual College student Program design competition in Henan province

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.