LightOJ-1002-Country Roads [最短路][Dijkstra]
来源:互联网 发布:沙钢收购大数据 编辑:程序博客网 时间:2024/05/25 21:33
题目传送门
题意:给定无向图,求一个城市t到其他城市的最低成本,成本的定义为路径中的最大消费。
思路:这个题跟POJ-2253-Frogger类似,可以用Dijkstra算法变形来写。也可以用kruskal来写。
#include <bits/stdc++.h>using namespace std;int n, m;int mp[550][550];const int INF = 0x3f3f3f3f;void Dij(int x){ int dis[550]; bool vis[550]; memset(dis, INF, sizeof(dis)); memset(vis, false, sizeof(vis)); for (int i = 0; i < n; i++) dis[i] = mp[x][i]; vis[x] = true; dis[x] = 0; for (int i = 0; i < n; i++) { int mi = INF; int f = -1; for (int j = 0; j < n; j++) { if (!vis[j] && dis[j] < mi) { mi = dis[j]; f = j; } } if (f==-1) break; vis[f] = 1; for (int j = 0; j < n; j++) { if (!vis[j] && dis[j] > max(dis[f],mp[f][j])) { dis[j] = max(dis[f], mp[f][j]); } } } for (int i = 0; i < n; i++) { if (dis[i]<INF) printf("%d\n",dis[i]); else printf("Impossible\n"); } return ;}int main(void){ int T, cas = 1; scanf("%d", &T); while (T--) { memset(mp, INF, sizeof(mp)); scanf("%d %d", &n, &m); while (m--) { int x, y, s; scanf("%d %d %d", &x, &y, &s); if (mp[x][y] >= s) mp[x][y] = mp[y][x] = s; } int p; scanf("%d", &p); printf("Case %d:\n",cas++); Dij(p); } return 0;}
阅读全文
0 0
- LightOJ-1002-Country Roads [最短路][Dijkstra]
- 【最短路】 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(最短路变形(SPFA||贝尔曼))
- lightOJ 1002:Country Roads
- LightOj 1002 - Country Roads
- 【LightOJ 1002】 Country Roads
- LightOJ 1002 Country Roads
- 1002 - Country Roads(lightoj)
- LightOJ 1002(最短路Dijkstra算法)
- LightOJ1002---Country Roads (最短路变形)
- LightOJ - 1002 Country Roads(最小瓶颈路)
- Lightoj1002——Country Roads(最短路变形)
- 【poj 1724】 ROADS 最短路(dijkstra+优先队列)
- LIGHTOJ 1002 – COUNTRY ROADS 【求最大边最小的路径】
- Linux下查看进程打开的文件句柄数
- hdu 3037 Saving Beans (Lucas)
- 谈谈ObjectiveC中__block
- SQL SERVER与C#数据类型对照表
- 李炎恢的bootstrap项目实战首页内容下思路解析
- LightOJ-1002-Country Roads [最短路][Dijkstra]
- Tracert 抓包测试
- HDU 1829 A Bug's Life(带权并查集)
- 实现RxBus代替EventBus
- I
- SpringBoot启动时报org.springframework.context.annotation.ConflictingBeanDefinitionException解决方法
- Jsp-Servlet常见 两种 页面间传递数据方式(request转发和session)
- P1071 潜伏者
- Spark RDD基础(二)之常见的转化操作和行动操作及持久化