0 < M < =5000
解析
本来一看还以为是最短路,但是最短路会使某些情况不能实现..
那么我们就要用一种特殊的方法..
我们先将全部边从小到大排序,然后我们就枚举最小的边是哪条,通过最小生成树取到最大的边,那么最小的比值就一目明了了。。
/************************************************************** Problem: 1050 User: chenyushuo2012 Language: C++ Result: Accepted Time:8060 ms Memory:936 kb ****************************************************************/ #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; int fa[510]; int ffa ( int x ){ if ( fa[x] == x ) return x; return fa[x] = ffa (fa[x]); } struct node { int x, y, d; }a[11000]; int n, m; bool cmp ( node x, node y ){ return x.d < y.d; } int st, ed; int ans_x, ans_y; int gcd ( int x, int y ){ if ( x == 0 ) return y; return gcd ( y%x, x ); } int main (){ int i, j, k; scanf ( "%d%d", &n, &m ); for ( i = 1; i <= m; i ++ ){ scanf ( "%d%d%d", &a[i].x, &a[i].y, &a[i].d ); } sort ( a+1, a+m+1, cmp ); scanf ( "%d%d", &st, &ed ); ans_x = 9999999; ans_y = 1; for ( i = 1; i <= m; i ++ ){ for ( j = 1; j <= n; j ++ ) fa[j] = j; for ( j = i; j <= m; j ++ ){ int xx = a[j].x, yy = a[j].y; fa[ffa(xx)] = ffa(yy); if ( ffa (st) == ffa (ed) ){ if ( a[j].d * ans_y < a[i].d * ans_x ){ ans_y = a[i].d; ans_x = a[j].d; k = gcd ( ans_x, ans_y ); ans_x /= k; ans_y /= k; break; } } } } if ( ans_y == 1 ){ if ( ans_x == 9999999 ) printf ( "IMPOSSIBLE\n" ); else printf ( "%d\n", ans_x ); } else printf ( "%d/%d\n", ans_x, ans_y ); return 0; }