山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
来源:互联网 发布:养成游戏源码 编辑:程序博客网 时间:2024/05/07 20:31
Emergency
Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^
题目描述
Now, she is facing an emergency in her hometown:
Her mother is developing a new kind of spacecraft. This plan costs enormous energy but finally failed. What’s more, because of the failed project, the government doesn’t have enough resource take measure to the rising sea levels caused by global warming, lead to an island flooded by the sea.
Dissatisfied with her mother’s spacecraft and the government, civil war has broken out. The foe wants to arrest the spacecraft project’s participants and the “Chief criminal” – Kudo’s mother – Doctor T’s family.
At the beginning of the war, all the cities are occupied by the foe. But as time goes by, the cities recaptured one by one.
To prevent from the foe’s arrest and boost morale, Kudo and some other people have to distract from a city to another. Although they can use some other means to transport, the most convenient way is using the inter-city roads. Assuming the city as a node and an inter-city road as an edge, you can treat the map as a weighted directed multigraph. An inter-city road is available if both its endpoint is recaptured.
Here comes the problem
Given the traffic map, and the recaptured situation, can you tell Kudo what’s the shortest path from one city to another only passing the recaptured cities?
输入
The input consists of several test cases.
The first line of input in each test case contains three integers N (0<N≤300), M (0<M≤100000) and Q (0<Q≤100000), which represents the number of cities, the numbers of inter-city roads and the number of operations.
Each of the next M lines contains three integer x, y and z, represents there is an inter-city road starts from x, end up withy and the length is z. You can assume that 0<z≤10000.
Each of the next Q lines contains the operations with the following format:
a) 0 x – means city x has just been recaptured.
b) 1 x y – means asking the shortest path from x to y only passing the recaptured cities.
The last case is followed by a line containing three zeros.
输出
For each operation 0, if city x is already recaptured (that is,the same 0 x operation appears again), print “City x is already recaptured.”
For each operation 1, if city x or y is not recaptured yet, print “City x or y is not available.” otherwise if Kudo can go from city x to city y only passing the recaptured cities, print the shortest path’s length; otherwise print “No such path.”
Your output format should imitate the sample output. Print a blank line after each test case.
示例输入
3 3 60 1 11 2 10 2 31 0 20 00 21 0 21 2 00 20 0 0
示例输出
Case 1:City 0 or 2 is not available.3No such path.City 2 is already recaptured.
弗洛伊德求最短路
#include <bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;bool vis[350];int Map[350][350];int main(){ int n,m,Q; int cas = 0; while(~scanf("%d %d %d",&n,&m,&Q) && (n || m || Q)) { memset(vis, false, sizeof(vis)); memset(Map, INF, sizeof(Map)); for(int i = 0; i < n; i++) Map[i][i] = 0; for(int i = 0; i < m; i++) { int u, v, w; scanf("%d %d",&u, &v); scanf("%d",&w); Map[u][v] = min(w, Map[u][v]); } printf("Case %d:\n",++cas); while(Q--) { int p, x, y, pos; scanf("%d",&p); if(p) { scanf("%d %d",&x, &y); if(!vis[x] || !vis[y]) printf("City %d or %d is not available.\n",x, y); else if(x == y) printf("0\n"); else { if(Map[x][y] == INF) printf("No such path.\n"); else printf("%d\n",Map[x][y]); } } else { scanf("%d",&pos); if(vis[pos]) printf("City %d is already recaptured.\n",pos); else { vis[pos] = true; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) Map[i][j] = min(Map[i][pos] + Map[pos][j] , Map[i][j]); } } } printf("\n"); } return 0;}
- 山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
- Emergency(山东省第一届ACM省赛)
- 山东省第一届ACM省赛 Emergency
- 山东省第七届 ACM 省赛 Proxy (最短路)
- 山东省第一届ACM省赛 C SDUT 2153 Clockwise
- 山东省第一届ACM省赛 D SDUT 2154 Shopping
- 山东省第一届ACM省赛 F SDUT 2156 Fairy tale
- 山东省第一届ACM省赛 J SDUT 2160 Jerry Mouse
- 山东省第一届ACM大学生程序设计竞赛 Emergency floyd变形
- 山东省第一届ACM省赛 A SDUT 2151 Phone Number(暴力)
- 山东省第一届ACM省赛 B SDUT 2152 Balloons(简单的BFS)
- 山东省第一届ACM省赛 G SDUT 2157 Greatest Number(暴力枚举)
- 山东省第一届ACM省赛 H SDUT 2158 Hello World!(穷举)
- 山东省第一届ACM省赛 I SDUT 2159 Ivan comes again!(STL-set)
- 第一届省赛 Emergency 最短路
- Balloons(山东省第一届ACM省赛)
- Shopping(山东省第一届ACM省赛)
- 山东省第一届ACM省赛 C SDUT 2153 Clockwise(dp+计算几何)
- Android开发像素相关知识
- Problem B: 出栈顺序(栈和队列)
- SQL语句的执行顺序
- Xcode7.2如何真机调试iOS 9.3的设备
- 对某次比赛里PWN的分析
- 山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
- 平均查找长度详解
- 无根树转有根树
- iOS与OS X内存管理
- 决策树算法学习笔记
- Python网络爬虫——模拟登陆爬取网站数据并加载到excl表格里
- activiti自定义流程之整合(二):使用angular js整合ueditor创建表单
- 用快速使用Python写一个拼写检查器
- MySQL5.7设置root密码