样例1
4 2
1 2 1
3 4 2
1 4
样例2
3 3
1 2 10
1 2 5
2 3 8
1 3
样例3
3 2
1 2 2
2 3 4
1 3
样例1
IMPOSSIBLE
样例2
5/4
样例3
2
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100100
struct node{
int u,v,w;
bool operator < (const node &a) const {
return w<a.w; }
}e[N];
int n,m,S,T,fa[N];
int find(int x)
{
return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++) scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
scanf("%d%d",&S,&T);
sort(e+1,e+m+1);
double ans=1e9;
bool flag=0;
int tx,ty,gg;
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++) fa[j]=j;
for(int j=i;j;j--){
int fx=find(e[j].u),fy=find(e[j].v);
if(fx!=fy) fa[fy]=fx;
if(find(S)==find(T)){
double tmp=(double)e[i].w/(double)e[j].w;
if(ans>tmp)
{
ans=tmp;
tx=e[i].w;
ty=e[j].w;
}
flag=1;
break;
}
}
}
if(!flag) puts("IMPOSSIBLE");
else {
if(tx%ty==0) printf("%d\n",tx/ty);
else {
gg=__gcd(tx,ty);
printf("%d/%d\n",tx/gg,ty/gg);
}
}
}