POJ 1861 Network Problem Solving report

Source: Internet
Author: User
Tags define local integer numbers

Network
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 16171 Accepted: 6417 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

[Submit]   [Go back]   [Status] [Discuss]

Home Page Go back to top

———————————————— I'm a split line ————————————————

The minimum spanning tree.

I didn't see special judge at first.

The results are different from the sample output, thinking that they were wrong and changed for a long time.

Finally, I can't stand the strong hand over the TAT.

A mouthful of poison milk has been sprayed out ......... .......

It is necessary to read the question carefully, even the topic of the topic.

Say why so many questions are called network ...

1 /*2 problem:3 OJ:4 User:5 Time :6 Memory:7 Length:8 */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <cmath> -#include <algorithm> -#include <queue> the#include <cstdlib> -#include <iomanip> -#include <cassert> -#include <climits> +#include <vector> -#include <list> +#include <map> A #defineMAXN 15001 at #defineF (i,j,k) for (int i=j;i<=k;i++) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (int i=j;i>=k;i--) - #defineINF 0x7fffffff - #defineMAXM 2016 - #defineMoD 1000000007 in //#define LOCAL - using namespacestd; to intRead () { +     intx=0, f=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} the      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} *     returnx*F; $ }Panax Notoginseng intn,m; - structEDGE the { +     int  from; A     intto ; the     intvalue; + }E[MAXN]; - intFA[MAXN]; $ intans[maxn],cnt; $ intNum,maxedge; -InlinevoidInit () - { the      for(intI=1; i<=n;i++) fa[i]=-1; - }WuyiInlineintFindintu) the { -     inti; Wu      for(i=u;fa[i]>=0; i=fa[i]); -      while(I!=u) {//Path Compression About         inttemp=Fa[u]; $fa[u]=i; -u=temp; -     } -     returni; A } +InlinevoidUnion (intAintb) the { -     intAa=find (a), bb=find (b); $     inttemp=fa[aa]+FA[BB]; the     if(FA[AA]&GT;FA[BB])//Merge by Rank the     { thefa[aa]=BB; thefa[bb]=temp; -     } in     Else{ thefa[bb]=AA; thefa[aa]=temp; About     } the } the intCompConst void*a,Const void*b) the { +EDGE aa=* (ConstEDGE *) A; -EDGE bb=* (ConstEDGE *) b; the     returnaa.value-Bb.value;Bayi } the intCMP (EDGE A,edge B) the { -     returna.value<B.value; - } theInlinevoidKruskal () the { theCnt=0; the     intu,v; - init (); the      for(intI=0; i<m;i++) the     { theU=e[i]. from; v=e[i].to;94         if(Find (u)! =Find (v)) the         { theans[cnt]=i;cnt++; the             if(e[i].value>Maxedge)98Maxedge=E[i].value; Aboutnum++; - Union (U,V); 101         }102         if(num>=n-1) Break;103     }104 }  the intMain ()106 {107Std::ios::sync_with_stdio (false);//cout<<setiosflags (ios::fixed) <<setprecision (1) <<y;108 #ifdef LOCAL109Freopen ("data.in","R", stdin); theFreopen ("Data.out","W", stdout);111     #endif the      while(cin>>n>>m)113     { the          for(intI=0; i<m;i++) Cin>>e[i]. from>>e[i].to>>E[i].value; theSort (e,e+m,cmp); the //qsort (e,m,sizeof (e[0]), comp);117Maxedge=0; num=0;118 Kruskal ();119cout<<maxedge<<Endl; -cout<<num<<Endl;121          for(intI=0; i<num;i++) Cout<<e[ans[i]]. from<<" "<<e[ans[i]].to<<Endl;122     }123     return 0;124}
POJ 1861

POJ 1861 Network Problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.