1079 go home, happy consumer fun 1079

Source: Internet
Author: User

1079 go home, happy consumer fun 1079
1079 back home

 

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

It's dinner time, and cows are scattered outside the farm. John the farmer rang the bell, so they started to go to the barn. Your job is to identify which cow will arrive in the Barn first (there will always be and only one of the fastest cows in the given test data ). During milking (before dinner), every cow is on her farm, and some pastures may have no cows. Each farm is connected to one or more farms by one road (may include itself ). Sometimes there is more than one road between two pastures (which may be the same letter. There must be at least one farm and a barn with a road connection. Therefore, all cows can reach the barn at last, and the cows always take the shortest path. Of course, cows can move in any direction at the same speed. The farm is marked as 'A'... 'Z' and 'A'... 'y'. There is a cow in the farm indicated by uppercase letters, but not in lowercase letters. The tag of the barn is 'Z'. Note that there are no cows in the barn.

Note that 'M' and 'M' are not the same farm.Otherwise ErrorThe above indicates that the input data may contain both M and m (depressing ing), for example

M a m z

Input description Input Description

Row 1st: integer P (1 <= P <= 10000), indicating the number of roads connecting the farm (Barn.

2nd. P + 1 line: two letters separated by space and an integer:

The length of the flag and road connecting to the farm by road (1 <= length <= 1000 ).

Output description Output Description

A separate row contains two items: the marker of the farm where the cows first arrive at the Barn are located, and the length of the path that the cows walk through.

Sample Input Sample Input

5

A d 6

B d 3

C e 9

D Z 8

E Z 3

Sample output Sample Output

B 11

Data range and prompt Data Size & HintCATEGORY tag Tags click here to expand

Flyoed

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int MAXN=123; 6 const int maxn=0x7fffffff; 7 int map[MAXN+10][MAXN+10];  8 char x,y; 9 int w;10 int main()11 {12     int n;13     scanf("%d",&n);14     for(int i=65;i<=MAXN+5;i++)15         for(int j=65;j<=MAXN+5;j++)16             map[i][j]=maxn;17     /*char huiche;18     char huiche;19     scanf("%c",&huiche);*/20     for(int i=1;i<=n;i++)21     {22         cin>>x;23         cin>>y;24         cin>>w;25         if(w<map[x][y])26         {27             map[x][y]=w;28             map[y][x]=w;29         }30         31     }32     for(int k=65;k<=122;k++)33     {34         for(int i=65;i<=122;i++)35         {36             for(int j=65;j<=122;j++)37             {38                 if(map[i][k]!=maxn&&map[k][j]!=maxn)39                 if(map[i][j]>map[i][k]+map[k][j])40                 {41                     map[i][j]=map[i][k]+map[k][j];42                 }43             }44         }45     }46     char ans;47     int minn=maxn;48     for(int i=65;i<=90-1;i++)49     {50         if(map['Z'][i]<minn)51         {52             minn=map['Z'][i];53             ans=i;54         }55     }56     //printf("%c %d",&ans,&minn);57     cout<<ans<<" "<<minn;58     return 0;59 }

 

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.