Network
Time Limit: 1000MS |
|
Memory Limit: 30000K |
Total Submissions: 14021 |
|
Accepted: 5484 |
|
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
Title Analysis: The original topic of Peking University POJ problem, sample output is wrong. At first I didn't know how the output of that sample came out!
After all, 4 nodes require only 3 edges to be fully connected, while the example is 4. Read a few people on the Internet blog to know that the Gregorian calendar is wrong. And
The scheme for the edges of the output spanning tree is not unique. The result of my output is this:
Accepted code is as follows: (the first runtime error, the structure of the array is small, note: The maximum number of edges is: 15,000, while the points are: 1000)
#include <stdio.h> #include <string.h> #include <iostream> #include <string> #include < Algorithm>using namespace std;//template Kruskal algorithm struct node{int u; int V; int W; BOOL operator < (const node &x) Const {return w<x.w; }}q[15002];int e;int fa[1002];int dd[1002][2], k=0;int findset (int x) {return fa[x]!=x?fa[x]=findset (Fa[x]): x;} int main () {int n, m; scanf ("%d%d", &n, &m); int I, J; e=0; for (i=0; i<m; i++) {scanf ("%d%d%d", &q[e].u, &Q[E].V, &Q[E].W); e++; } sort (q+0, q+e); for (i=0; i<=n; i++) {fa[i]=i; } int cnt=0; Number of sides counter int mm; Save the max path weight for (j=0; j<e; J + +) {if (Findset (q[j].u)! = Findset (Q[J].V)) { fa[fa[q[j].u]] = FA[Q[J].V]; dd[k][0]=q[j].u; DD[K][1]=Q[J].V; k++; cnt++; if (cnt==n-1) {MM=Q[J].W; BreaK }}} printf ("%d\n%d\n", MM, CNT); for (i=0; i<k; i++) {printf ("%d%d\n", dd[i][0], dd[i][1]); } return 0;}
POJ 1861 Network (Kruskal algorithm + output minimum spanning tree in the longest side = = Last added Benquan * "Template" of the spanning tree)