Test instructions: Solves the minimum spanning tree, and the bottleneck edge on the minimum bottleneck spanning tree.
Idea: Just ask for the minimum spanning tree. The bottleneck edge is the one with the largest weight on the spanning tree.
1 //#include <bits/stdc++.h>2#include <cstdio>3#include <vector>4#include <iostream>5#include <algorithm>6 #defineINF 0x7f7f7f7f7 #definePII pair<int,int>8 #defineLL Long Long9 using namespacestd;Ten Const intn=16100; One A intSeq[n], a[n], b[n], w[n], pre[n]; - intcmpintAintb) - { the returnw[a]<W[b]; - } - - intFindintx) + { - returnPre[x]==x? x:pre[x]=find (Pre[x]); + } A at -vector<int>Edge; - intCalintNintm) - { - edge.clear (); - intans=0; in for(intI=0; i<=n; i++) pre[i]=i; - for(intI=0; i<m; i++) to { + intu=find (A[seq[i]); - intv=find (B[seq[i]); the if(u!=v) * { $Pre[u]=v;//is not the same connected block, it is connected. Panax Notoginsengans=Max (ans, w[seq[i]); - Edge.push_back (Seq[i]); the } + } A returnans; the } + - intMain () $ { $Freopen ("Input.txt","R", stdin); - intt, N, M; - the while(cin>>n>>m) - {Wuyi for(intI=0; i<m; i++) the { -seq[i]=i; Wuscanf"%d%d%d", &a[i], &b[i], &w[i]); - } AboutSort (seq,seq+m,cmp); $Cout<<cal (n, m) <<Endl; -cout<<n-1<<Endl; - for(intI=0; I<edge.size (); i++) - { A intq=Edge[i]; +printf"%d%d\n", A[q], b[q]); the } - $ } the return 0; the}
AC Code
POJ 1861 Network (MST)