LightOJ 1019 (FLoyd裸题)
来源:互联网 发布:算法提供者错误 编辑:程序博客网 时间:2024/06/12 21:06
题解:
模板题
代码
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 110;const int INF = 0x3f3f3f3f;int dis[N][N];int n, m, cas = 1;void init() { scanf("%d%d", &n, &m); memset(dis, 0x3f, sizeof(dis)); for (int i = 1; i <= n; i++) dis[i][i] = 0; int u, v, d; for (int i = 0; i < m; i++) { scanf("%d%d%d", &u, &v, &d); dis[u][v] = dis[v][u] = min(dis[u][v], d); }}void solve() { for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (dis[i][k] != INF && dis[k][j] != INF && dis[i][j] > dis[i][k] + dis[k][j]) dis[i][j] = dis[i][k] + dis[k][j]; if (dis[1][n] == INF) printf("Case %d: Impossible\n", cas++); else printf("Case %d: %d\n", cas++, dis[1][n]);}int main() { int test; scanf("%d", &test); while (test--) { init(); solve(); } return 0;}
题目
Description
Tanvir returned home from the contest and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming contest? After checking a bit he found that there is no brush in him room. So, he called Atiq to get a brush. But as usual Atiq refused to come. So, Tanvir decided to go to Atiq’s house.
The city they live in is divided by some junctions. The junctions are connected by two way roads. They live in different junctions. And they can go to one junction to other by using the roads only.
Now you are given the map of the city and the distances of the roads. You have to find the minimum distance Tanvir has to travel to reach Atiq’s house.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a blank line. The next line contains two integers N (2 ≤ N ≤ 100) and M (0 ≤ M ≤ 1000), means that there are N junctions and M two way roads. Each of the next M lines will contain three integers u v w (1 ≤ u, v ≤ N, w ≤ 1000), it means that there is a road between junction u and v and the distance is w. You can assume that Tanvir lives in the 1st junction and Atiq lives in the Nth junction. There can be multiple roads between same pair of junctions.
Output
For each case print the case number and the minimum distance Tanvir has to travel to reach Atiq’s house. If it’s impossible, then print ‘Impossible’.
Sample Input
2
3 2
1 2 50
2 3 10
3 1
1 2 40
Sample Output
Case 1: 60
Case 2: Impossible
- LightOJ 1019 (FLoyd裸题)
- LightOJ - 1019 Brush (V)(floyd)
- LightOJ 1174 Commandos(FLoyd)
- lightoj 1019 - Brush (V) 【最短路 floyd】
- LightOJ - 1174 Commandos(floyd)
- LIGHTOJ 1174 – COMMANDOS 【FLOYD】
- lightoj 1019
- LightOJ - 1019 Brush (V)
- LightOJ 1019 Brush (V)
- lightOJ 1019 - Brush (V)
- lightoj 1019 模板dijkstra
- LightOJ-1019-Brush (V)
- lightoj 1020 (博弈)
- lightoj(基础数学)
- LightOJ 1175 (BFS)
- LightOJ 1008 (规律)
- Lightoj 1045 (数学题)
- LightOJ 1294 (规律)
- 杭电1000
- 异常初探(三)
- 笨方法学python(ex1-17)--%,input,解包,读取,写文件
- 使用NFS文件系统实现数据同步
- (一)01汤姆猫小游戏
- LightOJ 1019 (FLoyd裸题)
- python中的 \r以及基于此实现简单的倒计时小程序
- [Thrift分析]
- ios 判断app 启动方式
- Swift 2.3 【Swift2OC & OC2Swift】
- Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
- iOS常用加密方法(aes、md5、base64)
- android项目里的R文件报错考虑思路
- mahout in Action2.2-给用户推荐图书(3)-评价推荐系统