codeforces #368 div 2 B. Bakery (暴力)
题意:n个城市,m条双向路,要从k条中选择一个,使得到其他n-k个城市中的某个城市的距离最短。
思路:直接暴力 枚举。1A
/* ***********************************************
Author :111qqz
Created Time :2016年08月20日 星期六 21时02分14秒
File Name :code/cf/#368/B.cpp
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair
using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
const int N =1E5+7;
int n,m,k;
vector <pair <int,LL> >edge[N];
int b[N];
bool cangku[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif
ios::sync_with_stdio(false);
cin>>n>>m>>k;
ms(cangku,false);
for ( int i = 1 ; i <= m ; i++)
{
int u,v;
LL w;
cin>>u>>v>>w;
edge[u].push_back(make_pair(v,w));
edge[v].push_back(make_pair(u,w));
}
if (k==0)
{
cout<<-1<<endl;
return 0 ;
}
for ( int i = 1 ; i <= k ; i++)
{
cin>>b[i];
cangku[b[i]] = true;
}
if (k==n)
{
cout<<-1<<endl;
return 0;
}
LL ans = inf;
for (int i = 1 ; i <= k ; i++)
{
int u = b[i];
int siz = edge[u].size();
for (int j = 0 ; j < siz ; j++)
{
int v = edge[u][j].fst;
if (cangku[v]) continue;
LL w = edge[u][j].sec;
ans = min(ans,w);
}
}
if (ans==inf) ans = -1;
cout<<ans<<endl;
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}