LightOJ 1002 Country Roads
来源:互联网 发布:淘宝儿童玩具大全 编辑:程序博客网 时间:2024/06/05 21:24
题意:给一个图,再给个点p,求其它各点到点p的距离
裸的单源最短路,新手专用
#include <bits/stdc++.h>using namespace std;const int INF = 1e9;int n;bool vis[505];int dis[505];int g[505][505];void spfa(int s){ for(int i = 0; i < n; i++) dis[i] = INF, vis[i] = false; queue<int> q; dis[s] = 0; vis[s] = true; q.push(s); while(!q.empty()) { int p = q.front(); q.pop(); vis[p] = false; for(int i = 0; i < n; i++) { if(dis[i] <= max(dis[p], g[p][i])) continue; dis[i] = max(dis[p], g[p][i]); if(vis[i]) continue; vis[i] = true; q.push(i); } }}int main(){ int T; scanf("%d", &T); for(int ca = 1; ca <= T; ca++) { int m; scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) g[i][j] = INF; for(int i = 0; i < m; i++) { int l, r, v; scanf("%d%d%d", &l, &r, &v); g[l][r] = g[r][l] = min(g[l][r], v); } int aim; scanf("%d", &aim); spfa(aim); printf("Case %d:\n", ca); for(int i = 0; i < n; i++) { if(dis[i] != INF) printf("%d\n", dis[i]); else printf("Impossible\n"); } } return 0;}
1 0
- lightOJ 1002:Country Roads
- LightOj 1002 - Country Roads
- 【LightOJ 1002】 Country Roads
- LightOJ 1002 Country Roads
- 1002 - Country Roads(lightoj)
- 【Dijkstra】-LightOJ-1002-Country Roads
- 【最短路】 LightOJ 1002 - Country Roads 变形
- lightoj 1002 Country Roads (Dijkstra变形)
- LightOJ - 1002 Country Roads(最小瓶颈路)
- LightOJ 1002 Country Roads 最短路变形
- LightOJ-1002-Country Roads [最短路][Dijkstra]
- lightoj 1002 - Country Roads(最短路变形)
- LIGHTOJ 1002 – COUNTRY ROADS 【求最大边最小的路径】
- LightOJ 1002 Country Roads(最短路变形(SPFA||贝尔曼))
- Light OJ 1002 - Country Roads
- Light OJ - 1002 - Country Roads 题解
- Light oj 1002 - Country Roads 迪杰斯特拉变形
- LightOJ1002-Country Roads -dijstra
- sql小结
- Week3-1Semantic similarity:Synonymy and other Semantic Relations
- php snmp counter64 无法显示
- Name for argument type [java.lang.String] not available, and parameter name information not found in
- 动态规划
- LightOJ 1002 Country Roads
- 安装操作系统centos6.5手动分区以及设置网络连通性
- git 的学习
- Android-SeekBar(拖动进度条)
- ubuntu14.10,解决按照最新版Gnome 15.10后,经典Gnome桌面字体问题!
- angular学习资源
- 当你的Windows系统运行速度减慢时
- CC Arithmetic Progressions (FFT + 分块处理)
- windows下常用命令