第一届省赛 Emergency 最短路
来源:互联网 发布:施瓦辛格巅峰力量数据 编辑:程序博客网 时间:2024/05/11 16:11
题目描述
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 with y 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 cityx 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 <iostream>#include <stdio.h>#include <string.h>using namespace std;const int INF=123456789;int map[310][310];bool vis[310];int N,M,Q;void Floyed(int x){ for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(map[i][j]>map[i][x]+map[x][j]) map[i][j]=map[i][x]+map[x][j];}int main(){ int cnt=1; while(scanf("%d%d%d",&N,&M,&Q)!=EOF) { if(N==0&&M==0&&Q==0) break; printf("Case %d:\n",cnt++); memset(vis,false,sizeof(vis)); int x,y,z; for(int i=0;i<N;i++) for(int j=0;j<N;j++) {map[i][j]=INF;map[i][i]=0;} for(int i=1;i<=M;i++) { scanf("%d%d%d",&x,&y,&z); if(map[x][y]>z) map[x][y]=z; } while(Q--) { int s; scanf("%d",&s); if(s==0) { scanf("%d",&x); if(vis[x]) printf("City %d is already recaptured.\n",x); else { vis[x]=true; Floyed(x); } } else { scanf("%d%d",&x,&y); if(vis[x]&&vis[y]) { if(map[x][y]!=INF) printf("%d\n",map[x][y]); else printf("No such path.\n"); } else printf("City %d or %d is not available.\n",x,y); } } printf("\n"); } return 0;}
- 第一届省赛 Emergency 最短路
- PAT--1003. Emergency (最短路)
- 1003. Emergency(最短路)
- 山东省第一届ACM省赛 E SDUT 2155 Emergency(最短路)
- NEFU 663 Emergency 最短路 floyd
- PAT 甲级 1003Emergency(Dijkstra最短路)
- pat 甲1003. Emergency(最短路)
- PAT(A)1003 Emergency(最短路+计数)
- 1003. Emergency (25) 最短路问题
- hznu 1439 Emergency(不断加入点,更新最短路)
- 【PAT】Emergency(最短路条数-SPFA)
- PAT (Advanced Level) 1003 - Emergency(单元最短路)
- hdu 2544 最短路(最短路第一弹)
- PAT 1003. Emergency (25) (求两点间最短路的条数)
- PAT 1003 Emergency(求最短路条数 和 第二关键词最大)
- PAT 1003. Emergency Dijkstra变形+求相等最短路的数量+特殊权重
- PAT 1003. Emergency 单源最短路
- 最短路上的统计(4.8 jzoj第一题)
- 腾讯移动游戏平台安卓v1.0.0
- sring 操作
- mysql学习笔记之七(数据操作语言DML)
- 设置ToggleButton、Switch、CheckBox和RadioButton的显示效果
- 终端输入 Shell 命令时可用的快捷键
- 第一届省赛 Emergency 最短路
- 3D Game Programming for Kids 学习笔记
- 推荐!国外程序员整理的Java资源大全 转载
- 你应该知道的浮点数基础知识
- BNUoj 4260 Trick or Treat (三分)
- HDU 1846 Brave Game 博弈水题
- Qt_ROS Package学习与修改
- 算法学习 - 01背包问题(动态规划C++)
- chrome修改默认安装路径