调试大法好!
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n,m,f[600],k1,k2;
struct edge{
int u,v;
double w;
}e[6000];
bool operator <(edge a,edge b){
return a.w<b.w;
}
void csh(){
for(int i=1;i<=n;i++)f[i]=i;
};
int find(int x){
return (x==f[x]? x: f[x]=find(f[x]));
}
void pl(int x,int y){
f[find(x)]=find(f[y]);
}
int main(){
cin>>n>>m;
for(int i=0;i<m;i++)
cin>>e[i].u>>e[i].v>>e[i].w;
cin>>k1>>k2;
sort(e,e+m);
//cout<<1<<' '<<e[0].w<<' '<<e[m-1].w<<endl;
csh();
for(int i=0;i<m;i++){
pl(e[i].u,e[i].v);
}
// cout<<find(k1)<<' '<<find(k2)<<endl;
if(find(k1)!=find(k2)){
cout<<"IMPOSSIBLE"<<endl;
return 0;
}
double an1=100000000,an2=1;
for(int i=0;i<m;i++){
csh();
int j,flag=0;
for(j=i;j!=m;j++){
pl(e[j].u,e[j].v);
int x=find(k1);
int y=find(k2);
if(x==y){
flag=1;
break;
}
}
if( (an1/an2)>(e[j].w/e[i].w) && flag ){
an1=e[j].w;
an2=e[i].w;
}
}
//cout<<an1<<' '<<an2<<endl;
int a1=an1,a2=an2;
if(a1%a2==0)cout<<a1/a2;
else {
int g=__gcd(a2,a1);
a1/=g;
a2/=g;
cout<<a1<<'/'<<a2;
}
return 0;
}