http://acm.hdu.edu.cn/showproblem.php?pid=2066
#include<iostream>
using namespace std;
const int Max=1000000000;
int map[1001][1001];
int sor[1001],dis[1001];
int N,M,t,s,d,pr;

void dijkstra(int s)
{
    
int dist[1001],mark[1001],i,j,min,index;
    
for(i=N;i<=M;i++)
    
{
        mark[i]
=0;
        dist[i]
=map[s][i];
    }

    mark[s]
=1;
    dist[s]
=0;
    
for(i=N;i<=M;i++)
    
{
        min
=Max;
        
for(j=N;j<=M;j++)
        
{
            
if(mark[j]==0 &&  dist[j]<min)
            
{
                min
=dist[j];
                index
=j;
            }

        }

        
if(min==Max)
            
break;
        mark[index]
=1;
        
for(j=N;j<=M;j++)
        
{
            
if(mark[j]==0 && dist[j]>dist[index]+map[index][j] )
                   dist[j]
=dist[index]+map[index][j];
        }

    }

    
for(i=1;i<=d;i++)
        
if(dist[dis[i]]<pr)
            pr
=dist[dis[i]];
}


int main()
{
    
int i,j,k,ds;
    
while(cin>>t>>s>>d)
    
{
        
for(i=1;i<=1000;i++)
            
for(j=1;j<=1000;j++)
                map[i][j]
=Max;
        M
=-1;
        N
=1002;
        
for(k=1;k<=t;k++)
        
{
            scanf(
"%d%d%d",&i,&j,&ds);
            
if(ds<map[i][j]) //?????????????????????????????WA??n??????????
                map[i][j]=map[j][i]=ds;
            
if(M<i)
                M
=i;
            
if(N>i)
                N
=i;
            
if(M<j)
                M
=j;
            
if(N>j)
                N
=j;
        }

        
for(k=1;k<=s;k++)
            scanf(
"%d",&sor[k]);
        
for(k=1;k<=d;k++)
            scanf(
"%d",&dis[k]);
        pr
=Max;
        
for(k=1;k<=s;k++)
            dijkstra(sor[k]);
        cout
<<pr<<endl;
    }

    
return 0;
}