HDU 20,661 person's trip (shortest way)

Source: Internet
Author: User

The journey of a man

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 26552 Accepted Submission (s): 9189


Problem description Although grass son is a road crazy (is in Hangzhou electric stay for more than a year, incredibly still will be lost in campus, sweat ~), but grass son still very much like travel, because in the journey will meet a lot of people (Prince Charming, ^0^), many things, but also enrich their experience, You can also see the 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 line 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, the grass wants to go where there are D;
Then there is a T-line, each line has three integer a,b,time, indicating that the drive between A and B cities is time hours; (1=< (A, B) there may be multiple paths between <=1000;a,b)
The next line of T+1 is the number of S, which indicates the city connected with the grass family;
The next line of T+2 has a number D, 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

#include <stdio.h>
#include <string.h>
#define INF 99999999
__int64 map[10005][10005],ivs[10005],dis[10005];
__int64 s[10005],d[10005],d;
__int64 Dis (__int64 n,__int64 m)
{
__int64 I,j,min,p,q=inf;
for (I=1; i<=m; i++)
Dis[i]=map[n][i];
Ivs[n]=1;
for (I=1; i<=m; i++)
{
Min=inf;
for (j=1; j<=m; j + +)
if (!ivs[j]&&min>dis[j])
{
P=j;
MIN=DIS[J];
}
Ivs[p]=1;
for (j=1; j<=m; j + +)
{
if (!ivs[j]&&dis[p]+map[p][j]<dis[j])
DIS[J]=DIS[P]+MAP[P][J];
}
}
for (I=1; i<=d; i++)
{
if (Q>dis[d[i]])
Q=dis[d[i]];
}
return q;
}
int main ()
{
__int64 T,s,i,j,a,b,c,n,m,k,min,max;
while (scanf ("%i64d%i64d%i64d", &t,&s,&d)!=eof)
{
for (I=1; i<=1000; i++)
for (j=1; j<=1000; j + +)
Map[i][j]=inf;
Min=inf;
max=0;
for (I=1; i<=t; i++)
{
scanf ("%i64d%i64d%i64d", &a,&b,&c);
if (map[a][b]>c)
Map[a][b]=c;
if (map[b][a]>c)
Map[b][a]=c;
if (max<a)
Max=a;
if (max<b)
Max=b;
}
for (I=1; i<=s; i++)
scanf ("%i64d", &s[i]);
for (I=1; i<=d; i++)
{
scanf ("%i64d", &d[i]);
if (Max<d[i])
Max=d[i];
}
for (I=1; i<=s; i++)
{
memset (ivs,0,sizeof (IVs));
K=dis (S[i],max);
if (min>k)
Min=k;
}
printf ("%i64d\n", min);
}
return 0;
}

HDU 20,661 person's trip (shortest way)

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.