A person's travel-floyd

Source: Internet
Author: User

A man's Journey time limit:1000/1000ms (java/other) Memory limit:32768/32768k (Java/other) total submission (s): Accepted Submission (s): 12Problem description Although grass is a road fetish (that is, in Hangzhou electric for more than a year, incredibly still will be lost in the campus, sweat ~), but grass son still very much like travel, because in the journey will meet a lot of people (Prince Charming, ^0^), a lot of things, Also can enrich their experience, but also can see beautiful scenery ... Grass wants to go to many places, she wants to go to the Tokyo Tower to see the night scene, to Venice to see movies, to see the Taro on Yangmingshan, go to New York pure snow, go to Paris to drink coffee letter, to Beijing to visit Meng Jiangnu ... See the winter vacation is coming, so a large period of time, can not be wasted ah, must give yourself good put a fake, but also can not waste training ah, so grass son decided in the shortest time to a place where they want to go! Because the house of grass is in a small town, there is no train passing by, so she can only go to the neighboring city by train (poor Ah ~).

Input data has more than one group, the first row of each group is three integers t,s and D, indicating that there is a T road, and the grass home adjacent to the city of S, where the grass wants to go to have D; then there is a T-line, each line has three integer a,b,time, indicating that the drive between a B city is Time hour; (1= < (b) <=1000;a,b may have multiple paths) followed by the number of S on line t+1, indicating that the city is connected to the grass family, and then the first line of T+2 has a D number, indicating that the grass wants to go to the place.

Output outputs the shortest time a grass can go to a favorite city.

Sample INPUT6 2 31 3 51 4 72 8 123 8 44 9 129 10 21 28 9 10

Sample Output9

Authorgrass
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>#defineINF 0x3f3f3f3f//four x 3F, one less timeoutusing namespacestd; ints[1001]; inte[1001]; intmap[1001][1001];intMain () {intS,t,d,n; intA,b,c;  while(~SCANF ("%d%d%d",&t,&s,&D) {memset (Map,inf,sizeof(map)); N=0;  for(intI=1; i<=t;i++) {scanf ("%d%d%d",&a,&b,&c); MAP[A][B]=min (map[a][b],c); Map[b][a]=min (map[a][b],c); N=Max (N,max (A, b)); Map[i][i]=0;//You Hua        }         for(intI=1; i<=s;i++) {scanf ("%d",&S[i]); }         for(intI=1; i<=d;i++) {scanf ("%d",&E[i]); }         for(intk=1; k<=n;k++)             for(intI=1; i<=n;i++)            {                if(map[k][i]!=INF) {                     for(intj=1; j<=n;j++) {Map[i][j]= Min (map[i][j],map[i][k]+Map[k][j]); }                 }            }        intminx=INF;  for(intI=1; i<=s;i++)             for(intj=1; j<=d;j++) {Minx=min (Map[s[i]][e[j]],minx); } printf ("%d\n", Minx); }    return 0;}

SOURCERPG Practice Competition

A person's travel-floyd

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.