LightOJ 1019 Brush (V) 最短路裸题
来源:互联网 发布:seo资源网 编辑:程序博客网 时间:2024/05/01 02:56
题目:http://www.lightoj.com/volume_showproblem.php?problem=1019
题意:求从1到n的最短路。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace std;const int N = 110, INF = 0x3f3f3f3f;struct edge{ int to, cost, next;}g[N*N*2];int cnt, head[N], dis[N];bool vis[N];int n, m, cas;void add_edge(int v, int u, int cost){ g[cnt].to = u, g[cnt].cost = cost, g[cnt].next = head[v], head[v] = cnt++; g[cnt].to = v, g[cnt].cost = cost, g[cnt].next = head[u], head[u] = cnt++;}int spfa(int s, int t){ memset(dis, 0x3f, sizeof dis); memset(vis, 0, sizeof vis); queue<int> que; que.push(s), dis[s] = 0, vis[s] = true; while(! que.empty()) { int v = que.front(); que.pop(); vis[v] = false; for(int i = head[v]; i != -1; i = g[i].next) { int u = g[i].to; if(dis[u] > dis[v] + g[i].cost) { dis[u] = dis[v] + g[i].cost; if(! vis[u]) que.push(u), vis[u] = true; } } } return dis[t];}int main(){ int t, a, b, c; scanf("%d", &t); while(t--) { cnt = 0; memset(head, -1, sizeof head); scanf("%d%d", &n, &m); for(int i = 0; i < m; i++) scanf("%d%d%d", &a, &b, &c), add_edge(a, b, c); int res = spfa(1, n); if(res == INF) printf("Case %d: Impossible\n", ++cas); else printf("Case %d: %d\n", ++cas, res); } return 0;}
0 0
- LightOJ 1019 Brush (V) 最短路裸题
- [最短路+水题]LightOJ 1019 - Brush (V)
- LIGHTOJ 1019 – BRUSH (V) 【最短路】
- LightOJ Brush (V) 1019【简单最短路】
- lightoj 1019 - Brush (V) 【最短路 floyd】
- LightOJ - 1019 Brush (V) (最短路) 水
- LightOJ 1019-Brush (V)【最短路,模板题】
- Light oj 1019 - Brush (V)【最短路裸题】
- Light oj 1019 - Brush (V)【最短路裸题】
- LightOJ - 1019 Brush (V)
- LightOJ 1019 Brush (V)
- lightOJ 1019 - Brush (V)
- LightOJ-1019-Brush (V)
- LightOJ - 1019 Brush (V)(floyd)
- Lightoj 1019 - Brush (V)【dijkstra+spfa】
- Lightoj1019——Brush (V)(最短路)
- lightoj 1174 - Commandos(最短路)
- LIGHTOJ 1018 Brush (IV)
- 【LintCode】翻转链表 II
- z-index无效的几种情况
- 屏蔽storm ui的kill功能
- cmd习惯颜色
- Android组件式开发(2)——实现网格布局的RadioButton矩阵
- LightOJ 1019 Brush (V) 最短路裸题
- android developer tiny share-20160908
- SQL Server 取日期时间部分
- 146. LRU Cache
- Linux内核源代码分析——Linux内核的入口
- java中的继承(向上转型)
- win10 vs2015 php源码编译
- iOS中保证线程安全的几种方式与性能对比
- 自定义控件三部曲之动画篇(十二)——animateLayoutChanges与LayoutTransition