您的位置:首页 > 其它

CodeForcesGym 100753E Change of Scenery

2015-10-05 19:23 405 查看

Change of Scenery

Time Limit: 10000ms
Memory Limit: 262144KB
This problem will be judged on CodeForcesGym. Original ID: 100753E
64-bit integer IO format: %I64d Java class name: (Any)

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn = 10010;
struct arc{
int to,cost,next;
arc(int x = 0,int y = 0,int z = -1){
to = x;
cost = y;
next = z;
}
}e[2010000];
int head[maxn],cnt[maxn],d[maxn],tot,N,M,K;
void add(int u,int v,int w){
e[tot] = arc(v,w,head[u]);
head[u] = tot++;
}
priority_queue<pii,vector<pii>,greater<pii>>q;
bool done[maxn];
void dijkstra(){
while(!q.empty()) q.pop();
memset(d,0x3f,sizeof d);
memset(cnt,0,sizeof cnt);
q.push(pii(d[1] = 0,cnt[1] = 1));
while(!q.empty()){
int u = q.top().second;
q.pop();
if(done[u]) continue;
done[u] = true;
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] > d[u] + e[i].cost){
d[e[i].to] = d[u] + e[i].cost;
cnt[e[i].to] = cnt[u];
q.push(pii(d[e[i].to],e[i].to));
}else if(d[e[i].to] == d[u] + e[i].cost)
cnt[e[i].to]++;
}
}
}
int main(){
int x,u,v,w;
while(~scanf("%d%d%d",&N,&M,&K)){
memset(head,-1,sizeof head);
while(K--) scanf("%d",&x);
for(int i = tot = 0; i < M; ++i){
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
dijkstra();
puts(cnt
> 1?"yes":"no");
}
return 0;
}
/*
3 3 3
1 2 3
1 2 1
2 3 2
1 3 3
4 5 2
1 4
1 2 2
2 4 1
1 3 1
3 4 2
1 4 2
*/


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: