nefu 663 Emergency(flord算法)
来源:互联网 发布:近代史书籍推荐 知乎 编辑:程序博客网 时间:2024/04/29 22:09
Emergency
Time Limit 3000ms
Memory Limit 65536K
description
Kudo’s real name is not Kudo. Her name is Kudryavka Anatolyevna Strugatskia, and Kudo is only her nickname.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?
input
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.
output
For each case, print the case number (1, 2 …) first.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.
sample_input
3 3 60 1 11 2 10 2 31 0 20 00 21 0 21 2 00 20 0 0
sample_output
Case 1:City 0 or 2 is not available.3No such path.City 2 is already recaptured.
代码:
#include <iostream>#include <cstdio>#include <cstring>#define INF 1000000000using namespace std;int root[310];int dist[310][310];int n;void init(){ for(int i=0; i<n; i++) for(int j=0; j<n; j++) { if(i!=j) dist[i][j]=INF; else dist[i][j]=0; }}void solve(int k){ int i,j; for(i=0;i<n;i++) //if(root[i]) { for(j=0;j<n;j++) //if(root[j]) dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]); }}int main(){ int m,p; int x,y,z; int t=1; while(scanf("%d%d%d",&n,&m,&p)!=EOF) { if(n==0&&m==0&&p==0) break; memset(root,0,sizeof(root)); init(); for(int i=0;i<m;i++) { scanf("%d%d%d",&x,&y,&z); if(dist[x][y]>z) dist[x][y]=z; } printf("Case %d:\n",t++); while(p--) { scanf("%d",&x); if(x==0) { scanf("%d",&y); if(!root[y]) { root[y]=1; solve(y); } else printf("City %d is already recaptured.\n",y); } else { scanf("%d%d",&y,&z); if(root[y]==0||root[z]==0) printf("City %d or %d is not available.\n",y,z); else { if(dist[y][z]<INF) printf("%d\n",dist[y][z]); else printf("No such path.\n"); } } } puts(""); } return 0;}
0 0
- nefu 663 Emergency(flord算法)
- NEFU 663 Emergency 最短路 floyd
- 【1867】最短路径问题 (Flord算法)(SDUT)
- nefu-84-五指山(扩展欧几里德算法)
- 图的Flord算法(图中点到点的最短距离
- 1003. Emergency (25)-PAT甲级真题(Dijkstra算法)
- Emergency (dijkstra 变形)
- 1003. Emergency (25)(*****)
- Emergency
- emergency
- Emergency
- Emergency
- Emergency
- PTA--哈利·波特的考试--最短路径--Flord算法
- PAT 1003. Emergency (25) Dijkstra算法 + DFS
- SDUT2155 Emergency(第一届省赛题)(弗洛伊德算法)
- (排序算法整理)NEFU 30/32
- NEFU 84 五指山 扩展欧几里得算法
- FragmentTabHost切换Fragment避免重新加载Fragment,即重复调用Fragment的onCreateView。
- 在多核或多处理器时代,为什么要特别 重视 Java 多线程 开发模式
- [webkit好文]getting-started-with-the-webkit-layout-code
- HTML5学习笔记简明版(10):废弃的元素和属性
- CakeSchema回调
- nefu 663 Emergency(flord算法)
- HTML5学习笔记简明版(11):新增的API
- linux下c语言url请求
- 关于编译原理中的follow集的计算
- 每天一个C++小程序(十八)--插入排序
- 对象串行化---XmlSerializer简介
- 使用HTML5/CSS3五步快速制作便签贴特效
- 好复杂的 VIOS lpar 报错: 00c9
- week after week----行到水穷处,坐看云起时