# bzoj 3732: Network

## 3732: Network

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 1880  Solved: 894

## 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

思路：因为要最大边最小所以很明显是跑最小瓶颈生成树。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 30000
#define LL long long
using namespace std;
LL maxn[MAXN];
int n,m,k,tot,num,numb;
struct nond{
int x,y,z;
}edge[MAXN];
edge[++tot].x=u;edge[tot].y=v;edge[tot].z=w;
}
void insert(int u,int v,int w){
}
int cmp(nond a,nond b){
return a.z<b.z;
}
int find(int x){
if(fa[x]==x)    return fa[x];
else return fa[x]=find(fa[x]);
}
void dfs(int x){
maxn[to[i]]=cap[i];
dfs(to[i]);
}
}
LL lca(int x,int y){
LL ans=-1;
if(deep[x]>deep[y])    swap(x,y);
while(deep[y]>deep[x]){
ans=max(ans,maxn[y]);
}
while(x!=y){
ans=max(ans,max(maxn[x],maxn[y]));
}
return ans;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=m;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
}
sort(edge+1,edge+1+tot,cmp);
for(int i=1;i<=n;i++)    fa[i]=i;
for(int i=1;i<=tot;i++){
int dx=find(edge[i].x);
int dy=find(edge[i].y);
if(dx==dy)    continue;
numb++;
fa[dx]=dy;
insert(edge[i].x,edge[i].y,edge[i].z);
if(numb==n-1)    break;
}
dfs(1);
for(int i=1;i<=k;i++){
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",lca(x,y));
}
}

posted @ 2017-08-21 08:32  一蓑烟雨任生平  阅读(180)  评论(0编辑  收藏  举报