Network
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 15268 |
|
Accepted: 5987 |
|
Special Judge |
Description
Andrew is working as system administrator and was planning to establish a new network in he company. There'll is N hubs in the company, they can is connected to each of the other using cables. Since each worker of the company must has access to the whole network, each hub must is accessible by cables from any oth ER hub (with possibly some intermediate hubs).
Since cables of different types be available and shorter ones are cheaper, it's necessary to make such a plan of hub con Nection, that's the maximum length of a single cable is minimal. There is another problem-not each hub can being connected to any other one because of compatibility problems and building g Eometry limitations. Of course, Andrew would provide you all necessary information about possible hub connections.
You is to help Andrew to find the "the" to connect hubs so, all above conditions is satisfied.
Input
The first line of the input contains, numbers:n-the number of hubs in the network (2 <= N <=) and M-the number of possible hub connections (1 <= M <= 15000). All hubs is numbered from 1 to N. The following M lines contain information about possible connections-the numbers of both hubs, which can be connected and The cable length required to connect them. Length is a positive integer number this does not exceed 106. There'll is no more than one-to-connect, hubs. A Hub cannot is connected to itself. There always is at least one and connect all hubs.
Output
Output first the maximum length of a cable in your hub connection plan (the value of your should minimize). Then output your Plan:first output p-the number of cables used and then output P pairs of an integer numbers-numbers of hub s connected by the corresponding cable. Separate numbers by spaces and/or line breaks.
Sample Input
4 61 2 11 3 11 4 22 3 13 4 12 4 1
Sample Output
141 21 32) 33 4
Source
Northeastern Europe 2001, Northern subregion title: give you n vertex m no edge. Let you ask for a spanning tree so that the maximum edge is as small as possible. Outputs the longest edge, the number of edges, and which edges. This is a special sentence, so it may not be the same as the sample output. Problem-solving idea: to find the minimum bottleneck spanning tree. When solved with the Kruskal algorithm. When the diagram is first connected, the last side to be added is the one you are seeking.
#include <stdio.h> #include <algorithm> #include <string.h> #include <iostream>using namespace std;const int MAXN = 1010;const int maxe = 15010;struct edge{int from,to,dist,idx; Edge () {} edge (int _from,int _to,int _dist,int _idx): From (_from), to (_to), Dist (_dist), idx (_IDX) {}}edges[maxe];struct set{int Pa,rela;} Sets[maxn];int Ans[maxn];bool cmp (Edge A,edge b) {return a.dist < b.dist;} void init (int n) {for (int i = 0; I <= N; i++) {SETS[I].PA = i; }}int Find (int x) {if (x = = SETS[X].PA) {return x; } int tmp = SETS[X].PA; SETS[X].PA = Find (TMP); return SETS[X].PA;} int main () {int n, m; while (scanf ("%d%d", &n,&m)!=eof) {init (n); int a,b,c; for (int i = 0; i < m; i++) {scanf ("%d%d%d", &a,&b,&c); Edges[i] = Edge (a,b,c,i); } sort (edges,edges+m,cmp); int cnt = 0; for (int i = 0; i < m; i++) {Edge & e = edges[i]; int Rootx, Rooty; Rootx = Find (E.from); Rooty = Find (e.to); if (Rootx = = Rooty) {continue; } SETS[ROOTY].PA = Rootx; ans[cnt++] = i; } printf ("%d\n", edges[ans[cnt-1]].dist); printf ("%d\n", CNT); for (int i = 0; i < cnt; i++) {printf ("%d%d\n", edges[ans[i]].from,edges[ans[i]].to); }} return 0;}
POJ 1861--network —————— "minimum bottleneck spanning tree"