1020 twins: The Twins donate their bodies

Source: Internet
Author: User

1020 twins: The Twins donate their bodies
1020 twins

 

Time Limit: 1 s space limit: 128000 KB title level: Gold Title Description Description

In the G city security war, the super twins Phantom001 and Phantom002 were dispatched as the third-layer defense to guard the hidden passages in the southern part of the inner city.

According to the message from the Protection Center, the enemy has a special moth to guard against the second layer, directly forcing the entrance to the southern end of the inner city. But a good spider has already planted a solid large network in each channel. No matter which channel the moth enters, he has only one dead end! (Because he cannot break away from the Super web)

Currently, 001 and 002 are respectively located in two channels. Each channel is connected through an internal channel. It takes some time to pass through each internal channel. When the special moth is trapped somewhere, 001 or 002 will quickly come to get it out (of course, the least time-consuming one ).

Both 001 and 002 want to complete the task as soon as possible, and they want to select a solution that can complete the task as soon as possible in the worst case.

 

Input description Input Description

First, an integer N (N <= 100) indicates the number of channels.

Next, three integers a, B, and t in each row in several rows indicate that Channel a and channel B are connected through an internal line, and the passing time is t. (T <= 100)

(Input ensures that each channel is connected directly or indirectly)

Output description Output Description

There are two different integers x1 and x2, which are respectively 001,002 locations. (If there are multiple solutions, output the smallest x1 solution. If x1 is the same, output the smallest x2 solution)

Sample Input Sample Input

3

1 2 5

2 3 10

3 1 3

Sample output Sample Output

1 2'

No read questions !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 using namespace std; 5 const int MAXN=10001; 6 const int maxn=0x7fffffff; 7 int map[MAXN][MAXN]; 8 int main() 9 {10     int n;11     scanf("%d",&n);12     for(int i=1;i<=n;i++)13         for(int j=1;j<=n;j++)14             map[i][j]=maxn;15     for(int i=1;i<=n;i++)16         map[i][i]=0;17     int x,y,z;18     while(cin>>x>>y>>z)19     {20         map[x][y]=z;21         map[y][x]=z;22     }23     for(int k=1;k<=n;k++)24     {25         for(int i=1;i<=n;i++)26         {27             for(int j=1;j<=n;j++)28             {29                 if(map[i][j]>map[i][k]+map[k][j]&&map[i][k]!=maxn&&map[k][j]!=maxn)30                 {31                     map[i][j]=map[i][k]+map[k][j];32                     map[j][i]=map[i][k]+map[k][j];33                 }34             }35         }36     }37     int ppp=0,pp=0;38     int tot=0;39     /*for(int k=1;k<=n;k++)40     {41         for(int i=1;i<=n;i++)42         {43             for(int j=1;j<=n;j++)44             {45                 if(max(map[i][k],map[k][j])>tot)46                 {47                     x=i;48                     y=j;49                     tot=max(map[i][k],map[k][j]);50                 }51             }52         }53     }*/54     int ans=maxn;55     for(int i=1;i<=n;i++)56     {57         for(int j=i+1;j<=n;j++)58         {59             int minnow=0;60             for(int k=1;k<=n;k++)61             {62                 minnow=max(minnow,min(map[i][k],map[j][k]));63             }64             if(ans>minnow)65             {66                 ppp=i;67                 pp=j;68                 ans=minnow;69             }70         }71     }72     printf("%d %d",ppp,pp);73     return 0;74 }

 

Related Article

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.