Title Description
Give you the N-point of the graph (1 <= N <= 15,000), recorded as: 1 ... N.
The figure has M-bars (1 <= m <= 30,000), and the length of the J-Bar is: D_j (1 < = D_j < = 1,000,000,000).
Now there are K queries (1 < = K < = 20,000).
The format of each query is: A B, which indicates the minimum value of the longest edge in all paths from point A to point B?
Input
First line: N, M, K.
2nd.. M+1: Three positive integers: X, Y, and D (1 <= X <=N; 1 <= Y <= N). Represents an edge with a length of D between X and Y.
Line m+2..m+k+1: Two integers a b per line, which indicates the minimum value of the longest edge in all paths from point A to point B?
Output
For each query, the minimum value for the longest edge of the output is what.
Sample input
6 6 8
1 2 5
2 3 4
3 4 3
1 4 8
2 5 7
4 6 2
1 2
1 3
1 4
2 3
2 4
5 1
6 2
6 1
Sample output
5
5
5
4
4
7
4
5
Exercises
Kruskal to reconstruct the tree. In Kruskal, if two points are not in a collection, create a new node as their ancestor's father, and the Bing of the edge as the point of the new node. In this way, the original problem becomes the point right for the X, y two-point LCA in this Kruskal reconstruction tree.
//Kruskal Reconstruction Tree#include <cmath>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;#definell Long LongConst intmaxn=200000+ -;intn,m,k,aa,bb,fat[maxn],cnt;intfir[maxn],to[maxn],nex[maxn],ecnt;intSON[MAXN],DEP[MAXN],SZ[MAXN],FA[MAXN],TOP[MAXN],VAL[MAXN];structnode{intx, Y, Z;} A[MAXN];voidAdd_edge (intUintv) {nex[++ecnt]=fir[u];fir[u]=ecnt;to[ecnt]=v;}intcmpConstNode &a,ConstNode &b) { returna.z<b.z;}intFatherintx) { if(X!=fat[x]) fat[x]=father (Fat[x]); returnfat[x];}voidDFS1 (intXintFintDeep ) {Dep[x]=Deep ; FA[X]=F; SZ[X]=1; intmaxson=-1; for(intE=fir[x];e;e=Nex[e]) { intv=To[e]; if(v==f)Continue; DFS1 (V,x,deep+1); SZ[X]+=Sz[v]; if(Sz[v]>maxson) maxson=sz[v],son[x]=v; }}voidDFS2 (intXintTopf) {Top[x]=Topf; if(!son[x])return ; DFS2 (Son[x],topf); for(intE=fir[x];e;e=Nex[e]) { intv=To[e]; if(v==fa[x]| | V==SON[X])Continue; DFS2 (V,V); }}template<typename t>voidRead (t&AA) { Charcc ll Ff;aa=0; Cc=getchar (); ff=1; while((cc<'0'|| Cc>'9') &&cc!='-') cc=GetChar (); if(cc=='-') ff=-1, cc=GetChar (); while(cc>='0'&&cc<='9') aa=aa*Ten+cc-'0', cc=GetChar (); AA*=ff;}voidKruskal () {sort (a+1, A +1+m,cmp); for(intI=1; i<=m;i++){ if(Father (a[i].x)! =father (A[I].Y)) { intFa=father (a[i].x), fb=father (A[I].Y); val[++cnt]=a[i].z; FAT[CNT]=fat[fa]=fat[fb]=CNT; Add_edge (FA,CNT); Add_edge (CNT,FA); Add_edge (FB,CNT); Add_edge (CNT,FB); } }}intLcaintXinty) { intF1=top[x],f2=Top[y]; while(f1!=F2) { if(dep[f1]<Dep[f2]) swap (F1,F2), swap (x, y); X=fa[f1];f1=Top[x]; } returnDep[x]<dep[y]?x:y;}intMain () {read (n), read (m), read (k); CNT=N; for(intI=1; i<=m;i++) Read (a[i].x), read (A[I].Y), read (A[I].Z); for(intI=1; i<=n;i++) fat[i]=i; Kruskal (); DFS1 (CNT,0,1);d FS2 (cnt,cnt); while(k--) {read (AA), read (BB); cout<<val[lca (AA,BB)]<<Endl; } return 0;}
"bzoj3732" Network