• POJ--2485 Highways


    The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem. They're planning to build some highways so that it will be possible to drive between any pair of towns without leaving the highway system. 

    Flatopian towns are numbered from 1 to N. Each highway connects exactly two towns. All highways follow straight lines. All highways can be used in both directions. Highways can freely cross each other, but a driver can only switch between highways at a town that is located at the end of both highways. 

    The Flatopian government wants to minimize the length of the longest highway to be built. However, they want to guarantee that every town is highway-reachable from every other town.

    Input

    The first line of input is an integer T, which tells how many test cases followed. 
    The first line of each case is an integer N (3 <= N <= 500), which is the number of villages. Then come N lines, the i-th of which contains N integers, and the j-th of these N integers is the distance (the distance should be an integer within [1, 65536]) between village i and village j. There is an empty line after each test case.

    Output

    For each test case, you should output a line contains an integer, which is the length of the longest road to be built such that all the villages are connected, and this value is minimum.

    Sample Input

    1
    
    3
    0 990 692
    990 0 179
    692 179 0

    Sample Output

    692
    题意:Flatopia岛要修路,这个岛上有n个城市,要求修完路后,各城市之间可以相互到达,且修的总路程最短,求所修路中最长的路段
    代码:
     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 int par[100000];
     5 struct note
     6 {
     7     int st;
     8     int endd;
     9     int quan;
    10 }p[100000];
    11 int find(int x)
    12 {
    13     if(x!=par[x])
    14       return par[x]=find(par[x]);
    15     return par[x];  
    16 }
    17 void unite(int a,int b)
    18 {
    19     int fa=find(a);
    20     int fb=find(b);
    21     if(fa!=fb)
    22       {
    23           par[fa]=fb;
    24       }
    25 }
    26 bool cmp(note x,note y)
    27 {
    28     return x.quan<y.quan;
    29 }
    30 int main()
    31 {
    32     int t,n;
    33     scanf("%d",&t);
    34     while(t--)
    35     {
    36         scanf("%d",&n);
    37         int k=0;
    38         for(int i=0;i<100000;i++)
    39           par[i]=i;
    40         for(int i=1;i<=n;i++)
    41           for(int j=1;j<=n;j++)
    42           {
    43                p[k].st=i;
    44                p[k].endd=j;
    45                scanf("%d",&p[k].quan);
    46                k++;
    47           } 
    48         sort(p,p+k,cmp);  
    49         int max=0;  
    50         for(int i=0;i<k;i++)
    51           if(find(p[i].st)!=find(p[i].endd))
    52             {
    53                 unite(p[i].st,p[i].endd);
    54                 if(p[i].quan>max)
    55                   max=p[i].quan;
    56             }
    57        printf("%d
    ",max);                
    58     }
    59     
    60     return 0;
    61 }
  • 相关阅读:
    Classic Source Code Collected
    Chapter 2 Build Caffe
    蓝屏代码大全 & 蓝屏全攻略
    AMD C1E SUPPORT
    DCU IP Prefether
    DCU Streamer Prefetcher
    adjacent cache line prefetch
    Hardware Prefetcher
    Execute Disable Bit
    Limit CPUID MAX
  • 原文地址:https://www.cnblogs.com/hss-521/p/7281857.html
Copyright © 2020-2023  润新知