HDU 2066 一个人的旅行 最短路问题
来源:互联网 发布:悉知还是知悉 编辑:程序博客网 时间:2024/06/05 15:40
这题写坑了。。居然写了一个点。。
不久是裸的SPFA么,居然敲屎了!
啥也不说了,贴代码!(AC 15MS)
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int INF = 0x7f7f7f;const int MAX = 1020;int start[MAX], dis[MAX];int que[MAX], tail, front, now, size;bool to[MAX];struct way{ int to, time;}tp;vector<way> adjmap[MAX];int bfs(int s){ tail = 0, front = 1; for(int i = 0; i < MAX; ++i) dis[i] = INF; que[0] = s, dis[s] = 0; while(tail < front){ now = que[tail++]; size = adjmap[now].size(); for(int i = 0; i < size; ++i){ tp = adjmap[now][i]; if(dis[tp.to] > dis[now] + tp.time){ dis[tp.to] = dis[now] + tp.time; que[front++] = tp.to; } } } int ans = INF; for(int i = 0; i < MAX; i++) if(to[i]) ans = min(dis[i], ans); return ans;}int main(){ int t, s, d, a, b, time, temp; while(~scanf("%d%d%d", &t, &s, &d)){ int ans = INF; memset(to, false, sizeof(to)); for(int i = 0; i < MAX; ++i) adjmap[i].clear(); while(t--){ scanf("%d%d%d", &a, &b, &time); adjmap[a].push_back((way){b, time}); adjmap[b].push_back((way){a, time}); } for(int i = 0; i < s; ++i) scanf("%d", start + i); for(int i = 0; i < d; ++i){ scanf("%d", &temp); to[temp] = true; } for(int i = 0; i < s; ++i) ans = min(ans, bfs(start[i])); printf("%d\n", ans); }}
- hdu 2066 一个人的旅行(Dijkstra求最短路问题)
- hdu 2066 一个人的旅行(最短路问题)
- HDU 2066 一个人的旅行 最短路问题
- HDU 2066(一个人的旅行) SPFA(最短路问题)
- HDU-2066 一个人的旅行 最短路
- hdu 2066 一个人的旅行(最短路)
- hdu 2066 一个人的旅行(最短路)
- hdu 2066 一个人的旅行(最短路)
- HDU - 2066- 一个人的旅行【最短路】
- HDU 2066 一个人的旅行(最短路的简单题)
- 【hdu 2066】 一个人的旅行 ( 最短路 Dijkstra)
- HDU 2066 一个人的旅行(最短路&Dijkstra)
- HDU--杭电--2066--一个人的旅行--最短路
- HDU 2066 一个人的旅行(最短路)
- HDU 2066一个人的旅行(dijk最短路)
- hdu 2066 一个人的旅行_最短路
- HDU-2066 一个人的旅行(图论,Floyd ,最短路)
- HDU 2066-一个人的旅行(最短路Dijkstra)
- HashMap的使用
- CV牛人牛事简介
- 杭电OJ_A+B
- preloader打印调试语句
- 电量统计之一:PowerProfile.java与power_profile.xml
- HDU 2066 一个人的旅行 最短路问题
- 带头节点单链表的所有操作(目前我所想到的),linux纯C实现
- color picker
- Mplayer/mencoder as application bundle for Mac OS X?
- KMP算法中的next函数的证明
- Lsnrctl命令参数
- 尝试写博客
- WIN8重见开始菜单(续)
- 3.11 pread函数-文件原子读