Test instructions The minimum value of the longest edge in the connected sub-graph of a graph with n points m edges
The longest edge in the smallest spanning tree, in effect. Because the longest edge of the smallest spanning tree must be the smallest of all spanning trees, then it becomes the smallest spanning tree. Do not be the sample pit to the sample is not the best solution is only the longest edge and the minimum spanning tree the longest Bensian and so on the topic is a special award directly with the smallest spanning
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int N = 1005, M = 15005 struct Edge{int u, V, W;} e[m];int Par[n], ea[n], N, M, NUM, Ans;bool CMP (Edge A, Edge b) {return A.W < B.W;} int Find (int x) {int r = x, tmp; while (Par[r] >= 0) r = par[r]; while (x! = r) {tmp = par[x]; Par[x] = r; x = tmp; } return R;} void Union (int u, int v) {int ru = find (u), rv = Find (v), TMP = Par[ru] + PAR[RV]; if (Par[ru] > PAR[RV]) par[ru] = RV, par[rv] = tmp; else PAR[RV] = ru, par[ru] = tmp;} void Kruskal () {memset (par,-1, sizeof (PAR)); for (int i = 1; I <= m; ++i) {int u = e[i].u, v = e[i].v; if (find (U) = Find (v)) {Ea[++num] = i; ans = max (ans, E[I].W); Union (U, v); } if (num >= n-1) break; }}int Main () {int u, V, W; while (~SCANF ("%d%d", &n, &m)) {for (int i = 1; I <= m; + +)i) {scanf ("%d%d%d", &u, &v, &w); e[i].u = u, e[i].v = V, e[i].w = w; } sort (e + 1, E + M + 1, CMP); ans = num = 0; Kruskal (); printf ("%d\n%d\n", ans, num); for (int i = 1; I <= num; ++i) {int j = ea[i]; printf ("%d%d\n", e[j].u, E[J].V); }} return 0;}
Network
Description
andrew is working as System Administrator and are planning to establish a new network in h Is 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 is available and shorter ones are Cheaper, it's necessary to make such a plan of the hub connection, 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.
EW to find the the-the-connect hubs so, all above conditions is satisfied.
Input
The 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.
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
POJ 1861 Network (implied minimum spanning tree printing scheme)