POJ-2387-Til the Cows Come Home [最短路]
来源:互联网 发布:火狐浏览器打不开淘宝 编辑:程序博客网 时间:2024/05/19 04:25
题目传送门
题意:输入一个无向图,求N到1的最短路径。
思路:最短路模板题。
#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <cmath>#include <queue>#include <map>#include <set>using namespace std;int mp[1200][1200], N, T;const int inf = 0x3f3f3f3f;void init(){ for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) mp[i][j] = inf;}void dij(int x){ int dis[1200], book[1200]; memset(book,0,sizeof(book)); for (int i = 1; i <= N; i++) dis[i] = mp[x][i]; book[x] = 1; for (int i = 1; i <= N; i++) { int mi = inf, f = -1; for (int j = 1; j <= N; j++) { if (!book[j] && dis[j]<mi) { mi = dis[j]; f = j; } } if (f==-1) break; book[f]=1; for (int j = 1; j <= N; j++) { if (!book[j] && dis[j]>dis[f]+mp[f][j]) { dis[j] = dis[f]+mp[f][j]; } } } printf("%d\n", dis[N]); return;}int main(void){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); while (~scanf("%d %d", &T, &N)) { init(); while (T--) { int x, y, s; scanf("%d %d %d", &x, &y, &s); if (mp[x][y]>s && mp[y][x]>s) mp[x][y] = mp[y][x] = s; } dij(1); } return 0; }
阅读全文
0 0
- POJ 2387Til the Cows Come Home(最短路)
- POJ 2387 Til the Cows Come Home 最短路-Dijkstra
- POJ 2387 || Til the Cows Come Home(最短路,dijkstra
- poj 2387 Til the Cows Come Home(最短路)
- poj 2387 Til the Cows Come Home -- 最短路dijstra
- POJ 2387 Til the Cows Come Home 最短路
- POJ 2387 Til the Cows Come Home【最短路】
- POJ 2387 Til the Cows Come Home (最短路)
- poj 2387 Til the Cows Come Home (最短路)
- poj 2387 Til the Cows Come Home (最短路)
- POJ 2387 Til the Cows Come Home 最短路 Dijstra
- POJ-2387 Til the Cows Come Home【最短路】
- POJ-2387-Til the Cows Come Home [最短路]
- poj Til the Cows Come Home (Dijkstra最短路~)
- 最短路----Til the Cows Come Home
- Til the Cows Come Home 【最短路】
- Til the Cows Come Home 【最短路】
- POJ 2387 - Til the Cows Come Home(单源最短路)
- C++ 闭包(closure)
- 常用的一些GIT指令
- SVN is already locked.
- allegro学习之绘制板框的时候定位孔如何放置以及对板边的距离为多少合适
- 一个简单粗暴的屏幕适配
- POJ-2387-Til the Cows Come Home [最短路]
- 面试相关
- 【LEDE】树莓派上玩LEDE终极指南-99-编译psutil,安装thefuck
- Excel常见神器的另类新解 “条件格式”OR“自定义数字格式”
- C++基础---友元
- camera2 (api2)打开预览过程(二)
- JVM(Java虚拟机)优化大全和案例实战
- android使用fir.im实现版本更新
- SSL验证时,CSR文件的生成