zoukankan      html  css  js  c++  java
  • Network()

    Network

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other)
    Total Submission(s) : 17   Accepted Submission(s) : 8
    Special Judge
    Problem Description
    Andrew is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole network, each hub must be accessible by cables from any other hub (with possibly some intermediate hubs).
    Since cables of different types are available and shorter ones are cheaper, it is necessary to make such a plan of hub connection, that 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 geometry limitations. Of course, Andrew will provide you all necessary information about possible hub connections.
    You are to help Andrew to find the way to connect hubs so that all above conditions are satisfied.
     
    Input
    The first line of the input contains two 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 are numbered from 1 to N. The following M lines contain information about possible connections - the numbers of two hubs, which can be connected and the cable length required to connect them. Length is a positive integer number that does not exceed 106. There will be no more than one way to connect two hubs. A hub cannot be connected to itself. There will always be at least one way to connect all hubs.
     
    Output
    Output first the maximum length of a single cable in your hub connection plan (the value you should minimize). Then output your plan: first output P - the number of cables used, then output P pairs of integer numbers - numbers of hubs connected by the corresponding cable. Separate numbers by spaces and/or line breaks.
     
    Sample Input
    4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1
     
    Sample Output
    1 4 1 2 1 3 2 3 3 4
     题解:
    一:找最小生成树的最小权值;
    二:生成这个数的数据组数;
    三:输出这些数据;
    这题样例是错的,无语;
    代码:
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 using namespace std;
     5 #define MAX(x,y) (x>y?x:y)
     6 const int MAXN=15010;
     7 struct Node{
     8     int s,e,c;
     9 };
    10 int cmp(Node a,Node b){
    11     return a.c<b.c;
    12 }
    13 Node dt[MAXN];
    14 int pre[1010];
    15 int pt[MAXN],k,flot,as;
    16 int find(int x){
    17     return pre[x]= x==pre[x]?x:find(pre[x]);
    18 }
    19 void add(int a,int b){
    20     pt[k++]=a;pt[k++]=b;
    21 }
    22 void initial(){
    23     memset(pre,0,sizeof(pre));
    24     k=0;flot=1;
    25     as=-1;
    26 }
    27 void merge(Node a){
    28         int f1,f2;
    29     if(!pre[a.s])pre[a.s]=a.s;
    30     if(!pre[a.e])pre[a.e]=a.e;
    31     f1=find(a.s);f2=find(a.e);
    32     if(f1!=f2){
    33         add(a.s,a.e);
    34         flot++;
    35         as=MAX(as,a.c);
    36         pre[f1]=f2;
    37     }
    38 }
    39 int main(){int N,M;
    40     while(~scanf("%d%d",&N,&M)){
    41         initial();
    42         for(int i=0;i<M;i++){
    43             scanf("%d%d%d",&dt[i].s,&dt[i].e,&dt[i].c);
    44         }
    45         sort(dt,dt+M,cmp);
    46         for(int i=0;i<M;i++){
    47             merge(dt[i]);
    48         }
    49         printf("%d
    %d
    ",as,k/2);
    50         for(int i=0;i<k;i+=2){
    51             printf("%d %d
    ",pt[i],pt[i+1]);
    52         }
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    JUnit5依赖注入与测试接口
    Python如何设计面向对象的类(下)
    JUnit5参数化测试的几种方式
    JUnit5的条件测试、嵌套测试、重复测试
    熬夜肝了一份 C++/Linux 开发学习路线
    适合普通大学生的 Java 后端开发学习路线
    二本,拿腾讯,阿里 offer 了
    适合普通大学生的前端学习路线
    41道计算机网络高频面试题(附带答案)
    在Rancher中修改K8S服务参数的万金油法则
  • 原文地址:https://www.cnblogs.com/handsomecui/p/4728511.html
Copyright © 2011-2022 走看看