HDU2544 最短路
来源:互联网 发布:巴西经济危机 知乎 编辑:程序博客网 时间:2024/04/30 07:53
感觉bellman 和 djikstra处理的时候都要注意是否双向= =
#include <cstdio>#include <iostream>#include <cstring>using namespace std;const int INF = 0x3f3f3f;const int MAX = 1e4 + 5;struct EDGE{ int from, to, cost; EDGE(int a = 0, int b = 0, int c = 0) : from(a), to(b), cost(c) {}};EDGE edge[MAX];int d[105];int n, m;int main(){ while (scanf("%d%d", &n, &m)) { if (n == 0 && m == 0) break; int cnt = 0; int t_from, t_to, t_cost; for (int i = 0; i < m; ++i) { scanf("%d%d%d", &t_from, &t_to, &t_cost); edge[cnt++] = EDGE(t_from, t_to, t_cost); edge[cnt++] = EDGE(t_to, t_from, t_cost); } memset(d, INF, sizeof(d)); d[1] = 0; while (true) { bool update = false; for (int i = 0; i < 2 * m; ++i) { EDGE e = edge[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update) break; } printf("%d\n", d[n]); } return 0;}
0 0
- Hdu2544-最短路-【最短路】
- hdu2544最短路
- hdu2544最短路
- hdu2544(最短路)
- hdu2544最短路
- hdu2544 Dijkstra最短路
- hdu2544-最短路
- hdu2544 最短路
- HDU2544:最短路
- hdu2544最短路
- hdu2544最短路
- hdu2544最短路
- HDU2544:最短路(Dijkstra)
- hdu2544 最短路
- hdu2544 最短路
- hdu2544 最短路
- HDU2544 最短路 【Dijkstra】
- HDU2544,最短路
- 如何使用Jenkins进行持续集成测试
- BZOJ_P3081 [Cerc2011]Strange Regulations(LCT)
- 十四、初学jsp之jsp九大隐式对象
- 查看Android版本的源代码
- bower初级入门
- HDU2544 最短路
- 十五、初学jsp之jsp EL表达式
- Eclipse修改默认编码格式:工作空间,工程,文件,某类文件(如jar)
- 解决电脑wlan被禁用无法再启动的办法.
- java集合框架
- POJ 3648 Wedding 2-SAT
- 梯度下降(Gradient Descent),一句代码,一个式子
- ViewDragHelper 实现 ListView 左滑删除
- 十六、初学jsp之jstl标签与自定义标签