Wikioi 1001

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值