answer
First, let's look at what is the bottleneck spanning tree :
Undirected graph G defined, G is a bottleneck spanning tree "tree weight maximum side edge in the minimum spanning tree of all the G" spanning tree, the spanning tree may be more than one such. Bottleneck spanning tree is a maximum side edge weight
Examples: Given an undirected graph G
which may be the bottleneck spanning a long way: their values are 2
Meaning of the title is actually asking you the minimum spanning tree of bottlenecks,
run it again to find the minimum spanning tree can be a maximum edge
:( prove two theorems want to know can go to Baidu)
1. Minimum spanning tree must be the bottleneck spanning tree
2. bottleneck spanning tree is not necessarily a minimum spanning tree, minimum spanning tree = minimum spanning tree bottleneck
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=1e3+10;
int n,m;
int g[N][N];
int dis[N],vis[N];
int prim() {
memset(dis, INF, sizeof dis);
memset(vis, 0, sizeof vis);
int res=0;
for (int i = 0; i <n ; i++) {
int f=-1;
for (int j = 1; j <= n; j++) {
if(!vis[j] && (f==-1 || dis[f]>dis[j]))
f=j;
}
if(i)res=max(res,dis[f]);
vis[f]=1;
for (int j = 1; j <= n; j++) {
dis[j]=min(dis[j],g[f][j]);
}
}
return res;
}
int main()
{
memset(g, INF, sizeof g);
cin>>n>>m;
for (int i = 1; i <= n; i++) {
g[i][i]=0;
}
for (int i = 1,u,v,c; i <= m; i++) {
cin>>u>>v>>c;
g[u][v]=g[v][u]=c;
}
printf("%d %d\n",n-1,prim());
return 0;
}