Networktime limit:2000/1000ms (java/other) Memory limit:60000/30000k (Java/other) total submission (s): Accepted Submission (s): 8Special Judgeproblem Descriptionandrew is working as system administrator and are 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 be connected to any other one because of compatibility problems and building GEO Metry 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.
Inputthe first line of the input contains double integer NUMBERS:N-the number of hubs in the network (2 <= N <= 1000 ) 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.
Outputoutput first the maximum length of a single 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 INPUT4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1
Sample OUTPUT1 4 1 2 1 3 2 3 3 4 Troubleshooting: First: Find the minimum weight of the minimum spanning tree; second: the number of data groups generating this number; three: outputting the data; The sample is wrong, no language; code:
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 #defineMAX (x, y) (x>y?x:y)6 Const intmaxn=15010;7 structnode{8 ints,e,c;9 };Ten intCMP (Node A,node b) { One returna.c<B.C; A } - Node DT[MAXN]; - intpre[1010]; the intPt[maxn],k,flot, as; - intFindintx) { - returnpre[x]= x==pre[x]?X:find (pre[x]); - } + voidAddintAintb) { -pt[k++]=a;pt[k++]=b; + } A voidInitial () { atmemset (PRE,0,sizeof(pre)); -k=0; flot=1; - as=-1; - } - voidmerge (Node a) { - intF1,f2; in if(!pre[a.s]) pre[a.s]=A.S; - if(!PRE[A.E]) pre[a.e]=A.E; toF1=find (A.S); f2=find (A.E); + if(f1!=F2) { - Add (A.S,A.E); theflot++; * as=max ( as, A.C); $pre[f1]=F2;Panax Notoginseng } - } the intMain () {intn,m; + while(~SCANF ("%d%d",&n,&M)) { A initial (); the for(intI=0; i<m;i++){ +scanf"%d%d%d",&dt[i].s,&dt[i].e,&dt[i].c); - } $Sort (dt,dt+m,cmp); $ for(intI=0; i<m;i++){ - merge (Dt[i]); - } theprintf"%d\n%d\n", as, k/2); - for(intI=0; i<k;i+=2){Wuyiprintf"%d%d\n", pt[i],pt[i+1]); the } - } Wu return 0; -}
Network ()