1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include<bits/stdc++.h> // 万能头文件
using namespace std;
int End[50100]; int Value[50100]; int Next[50100]; int Head[10100]; int q[50100]; int n, m, s, t; int qf, qe; bool Used[10100];
bool Check(int x){ memset(Used, false, sizeof(Used)); qf = qe = 1; q[1] = s; Used[s] = true; while(qf <= qe){ int xx = Head[q[qf]]; while(xx != -1){ if(!Used[End[xx]] && Value[xx] <= x){ q[++qe] = End[xx]; Used[End[xx]] = true; } xx = Next[xx]; } qf++; } return Used[t]; }
int main(){ memset(Next, -1, sizeof(Next)); memset(Head, -1, sizeof(Head)); scanf("%d %d %d %d", &n, &m, &s, &t); int r = 0; for(int i = 1; i <= m; i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); Value[i*2] = c; End[i*2] = b; Next[i*2] = Head[a]; Head[a] = i*2; Value[i*2+1] = c; End[i*2+1] = a; Next[i*2+1] = Head[b]; Head[b] = i*2+1; if(c > r) r = c; } r++; int l = 1; while(l < r){ int Mid = ((l+r) >> 1); if(Check(Mid)) r = Mid; else l = Mid+1; } printf("%d", l); }
|