Total Submission(s): 40926 Accepted Submission(s): 13919
接着有T行,每行有三个整数a,b,time,表示a,b城市之间的车程是time小时;(1=<(a,b)<=1000;a,b 之间可能有多条路)
接着的第T+1行有S个数,表示和草儿家相连的城市;
接着的第T+2行有D个数,表示草儿想去地方。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<memory.h>
#include<queue>
using namespace std;
queue<int>q;
const int Inf=0x3f3f3f3f;;
const int Maxm=3000100;
const int Maxn=1010;
int dis[Maxn],cnt,n,Min,c,dr;
int Laxt[Maxm],Next[Maxm],To[Maxm],Len[Maxm];
int conti[Maxn],dream[Maxn];
int Win[Maxn];
void _add(int u,int v,int d){
Next[++cnt]=Laxt[u];
Laxt[u]=cnt;
To[cnt]=v;
Len[cnt]=d;
Next[++cnt]=Laxt[v];
Laxt[v]=cnt;
To[cnt]=u;
Len[cnt]=d;
}
void _dij()
{
while(!q.empty()){
int s=q.front();
q.pop();
Win[s]=0;
for(int i=Laxt[s];i>0;i=Next[i]){
if(dis[s]+Len[i]<dis[To[i]])
{
dis[To[i]]=dis[s]+Len[i];
if(!Win[To[i]]) {
q.push(To[i]);
Win[To[i]]=1;
}
}
}
}
}
int main()
{
int m,i,j,k,x,y,z;
while(~scanf("%d%d%d",&m,&c,&dr))
{
memset(Laxt,0,sizeof(Laxt));
memset(Next,0,sizeof(Next));
memset(Win,0,sizeof(Win));
cnt=1;
for(i=1;i<=m;i++) {
scanf("%d%d%d",&x,&y,&z);
_add(x,y,z);
dis[x]=Inf;
dis[y]=Inf;
}
for(i=1;i<=c;i++) {
scanf("%d",&conti[i]);
dis[conti[i]]=0;
q.push(conti[i]);
Win[conti[i]]=1;
}
for(i=1;i<=dr;i++) {
scanf("%d",&dream[i]);
dis[dream[i]]=Inf;
}
_dij();
Min=Inf;
for(j=1;j<=dr;j++)
if(Min>dis[dream[j]]) {
Min=dis[dream[j]];
}
printf("%d\n",Min);
}
return 0;
}