var
n,m,i,s,t,xi,yi,flag:longint;
fa:array[0..500]of longint;
x,y,v:array[0..5000]of longint;
procedure sort(l,r:longint);
var
i,j,t,z:longint;
begin
i:=l;
j:=r;
z:=v[random(r-l)+l];
repeat
while v[i]>z do
inc(i);
while v[j]<z do
dec(j);
if i<=j then
begin
t:=x[i];
x[i]:=x[j];
x[j]:=t;
t:=y[i];
y[i]:=y[j];
y[j]:=t;
t:=v[i];
v[i]:=v[j];
v[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
function find(son:longint):longint;
begin
if fa[son]=son then exit(son);
fa[son]:=find(fa[son]);
exit(fa[son]);
end;
procedure try(step:longint);
var
i:longint;
begin
for i:=1 to n do
fa[i]:=i;
for i:=step to m do
begin
fa[find(x[i])]:=find(y[i]);
if find(s)=find(t) then
begin
inc(flag);
if flag=1 then
begin
xi:=v[step];
yi:=v[i];
end;
if (v[step]/v[i])<(xi/yi) then
begin
xi:=v[step];
yi:=v[i];
end;
end;
end;
end;
function gcd(a,b:longint):longint;
begin
if b=0 then exit(a);
exit(gcd(b,a mod b));
end;
procedure print;
begin
if (xi mod yi)=0 then
begin
write(xi div yi);
exit;
end;
write(xi div gcd(xi,yi),'/',yi div gcd(xi,yi))
end;
begin
randomize;
read(n,m);
for i:=1 to m do
read(x[i],y[i],v[i]);
read(s,t);
sort(1,m);
for i:=1 to m do
try(i);
if flag=0 then write('IMPOSSIBLE')
else print;
//end;
end.
Wikioi 1001
最新推荐文章于 2017-01-26 21:03:31 发布