CodeForcesGym 100753E Change of Scenery
2015-10-05 19:23
405 查看
Change of Scenery
Time Limit: 10000msMemory 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
相关文章推荐
- [转]Android中自定义checkbox样式
- 分享一下我电脑里的软件
- PL SQLDEVELOPMENT导出数据库脚本
- 无题(四):分割字符串(运用二维数组)
- 优化Myeclipse10 Building Workspace速度慢等
- 关于Trimmomatic
- usaco Starry Night
- 算法导论2-9章补充几道题
- 如何写科研文章
- Java虚拟机之垃圾回收详解一
- iOS--单例(Singleton)
- IOS 解析XML格式
- java记——判断语句
- POJ3259 Wormholes SPFA 或者 bellman_ford
- java记——判断句 计算个人所得税
- 随波逐流之IOS 复杂数据的归档和反归档 详解
- unity官方demo学习之Stealth(二十三)敌人射击功能
- static 使用之静态变量
- iOS 分享功能开发
- java记——随机数