可惜没如果=_= 不知那年的樱花树上，哪一瓣最美

## 3732: Network

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 2092  Solved: 998
[Submit][Status][Discuss]

## Output

对每个询问，输出最长的边最小值是多少。

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

5
5
5
4
4
7
4
5

## HINT

1 <= N <= 15,000

1 <= M <= 30,000

1 <= d_j <= 1,000,000,000

1 <= K <= 15,000

## Source

 1 #include "bits/stdc++.h"
2 using namespace std;
3 typedef long long LL;
4 const int MAX1=15005;
5 const int MAX2=30005;
6 int n,m,K,f[MAX1];
8 int fa[MAX1][21],gg[MAX1][21],deep[MAX1];
9 struct Edge{
10     int u,v,w;
11     bool operator < (const Edge &tt) const {
12         return w<tt.w;
13     }
14 }edge[MAX2];
16     int an=0,x=1;char c=getchar();
17     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
18     while (c>='0' && c<='9') {an=(an<<3)+(an<<1)+c-'0';c=getchar();}
19     return an*x;
20 }
21 inline int getfather(int x){return f[x]==x?x:f[x]=getfather(f[x]);}
22 void addedge(int u,int v,int w){
24 }
25 void dfs(int x,int ff){
26     int i,j;
27     for (i=1;i<=20;i++){
28         if (deep[x]<(1<<i)) break;
29         fa[x][i]=fa[ fa[x][i-1] ][i-1];
30         gg[x][i]=max(gg[x][i-1],gg[ fa[x][i-1] ][i-1]);
31     }
37         }
38     }
39 }
40 int lca(int x,int y){
41     int an=0,i,j;
42     if (deep[x]<deep[y]) swap(x,y);
43     int dd=deep[x]-deep[y];
44     for (i=20;i>=0;i--)
45         if (dd&(1<<i))
46             an=max(an,gg[x][i]),x=fa[x][i];
47     for (i=20;i>=0;i--){
48         if (fa[x][i]!=fa[y][i]){
49             an=max(an,max(gg[x][i],gg[y][i]));
50             x=fa[x][i],y=fa[y][i];
51         }
52     }
53     if (x!=y) an=max(an,max(gg[x][0],gg[y][0])),x=fa[x][0];
54     return an;
55 }
56 int main(){
57     freopen ("network.in","r",stdin);freopen ("network.out","w",stdout);
58     int i,j,u,v;tot=1;
61     sort(edge+1,edge+m+1);
62     for (i=1;i<=n;i++) f[i]=i;
63     for (i=1;i<=m;i++){
64         int tx=getfather(edge[i].u);
65         int ty=getfather(edge[i].v);
66         if (tx!=ty){
67             f[tx]=ty;
69         }
70     }
71     dfs(1,0);
72     for (i=1;i<=K;i++){
77 }