Emergency

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描述

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?

输入

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 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 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 6
0 1 1
1 2 1
0 2 3
1 0 2
0 0
0 2
1 0 2
1 2 0
0 20 0 0

示例输出

Case 1:
City 0 or 2 is not available.
3
No such path.
City 2 is already recaptured.

链接:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155

解题思路:

开始忘了用多源最短路了,于是乎SPFA果断TL

用floyd最短路就好了,由于点很少,所以直接矩阵保存就好了。。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;
#define MAX 500
#define INF 0x3f3f3f3f
int mmap[MAX][MAX];
int nodeMark[MAX];
int main (){int u,v,w;int N,M,Q,cnt=1;while(~scanf("%d%d%d",&N,&M,&Q)&&!(N==0&&M==0&&Q==0)){printf("Case %d:\n",cnt++);for(int i=0;i<N;i++)for(int j=0;j<N;j++)mmap[i][j]=( i==j ? 0 : INF);memset(nodeMark,0,sizeof(nodeMark));for(int i=0;i<M;i++){scanf("%d%d%d",&u,&v,&w);mmap[u][v]=min(w,mmap[u][v]);}int x,y,op;for(int i=0;i<Q;i++){scanf("%d",&op);if(op){scanf("%d%d",&x,&y);if(nodeMark[x]==0||nodeMark[y]==0){printf("City %d or %d is not available.\n",x,y);}else{if(mmap[x][y]==INF)  printf("No such path.\n");else printf("%d\n",mmap[x][y]);}}else{scanf("%d",&x);if(nodeMark[x]) printf("City %d is already recaptured.\n",x);else{nodeMark[x]=1;for(int i=0;i<N;i++)for(int j=0;j<N;j++)mmap[i][j]=min(mmap[i][x]+mmap[x][j],mmap[i][j]);}}}printf("\n");}return 0;
}

第一届 ACM省赛山东省 Emergency相关推荐

  1. 山东省第一届ACM省赛 H SDUT 2158 Hello World!(穷举)

    Hello World! Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We know that Ivan gives Saya ...

  2. 山东省第一届ACM省赛 C SDUT 2153 Clockwise

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  3. 2021-SZTU第一届acm校赛总结

    关于题目: 我们队上来找到签到题,一个上去签,我和另外一个继续看题,我从后往前,他从前往后.后边的题目普遍是中文,难度也更高.然后他们两个就讨论一题签一题,干掉四题.我看了一道区间操作相关的题目,最近 ...

  4. 2017年山东省ACM省赛总结

    2017年山东省ACM省赛总结 ----但求努力到问心无愧 这次比赛我们是作为友谊队去的,本来我们队选拔赛成绩并不是很好,是去不了的,但伟大的教主大人牛逼地又要到了几个省赛友谊队的名额,才让我们有这次 ...

  5. [2010山东ACM省赛] Greatest Number(数的组合+二分搜索)

    Greatest Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya likes math, because ...

  6. 2014 ACM省赛总结

    今年ACM省赛已经过去一个星期左右了,2年的ACM训练是该做个总结了,因为前几日去參加蓝桥杯总决赛,所以没来的及写总结,如今在这小小总结一下吧-- 依晰记得去年省赛时候的样子,如今感觉那时像是个无知的 ...

  7. ACM训练赛--递推专题

    1001: Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be ...

  8. 范围元【2013 GDCPC】有为杯 广东ACM省赛小总结

    文章结束给大家来个程序员笑话:[M] 第一次加入生赛,心情万分激昂,我不是大牛,但是在子畦大牛的率领下,刚好排到了校赛的第20名,升级省赛. 广东的ACM省赛弄得非常好,无论是职员安排还是举办方对参赛 ...

  9. 重庆师范大学第一届ACM选拔赛

    下面的题解不会给出题目所以在开头放出比赛链接传送门 本场比赛大部分都是模板题,但是任有记录的必要性 重庆师范大学第一届ACM选拔赛 不一样的食物链 有趣的求和 统计患病人数 皮皮想拜师 爱玩游戏的To ...

最新文章

  1. 欢迎参加城市大脑与智慧城市前沿趋势 主题论坛 |未来科技大讲堂 第12期
  2. 鹅厂2020暑期实习第二次二面
  3. [YTU]_2911(我想放假)
  4. Could not set property 'xxx' of 'class 'xxx' with value 'xxx'
  5. 高效程序员的45个习惯 pdf_高效瑜伽人的 5 个习惯,你get到了几个?
  6. 前端学习(1232):组件化开发开始
  7. php5.4 mysql connect_php5.4 Call to undefined function mysql_connect()
  8. Windows编程—杀死指定路径程序文件的进程
  9. netty发送对象消息
  10. Ubuntu下配置使用maven
  11. 搜狗开源最新NLP研究成果,打造业内最全机器阅读理解工具包SMRC
  12. scala学习手记15 - 独立对象和伴生对象
  13. 包含的前缀数目超过了最大值。最大值为 2_「西法带你学算法」一次搞定前缀和...
  14. linux实训4文件系统管理,实训项目2 Linux文件系统管理
  15. HTML5、css3、js实现3D相册
  16. 如何在互联网上虚度人生?
  17. pinyin4j:拼音与汉字的转换实例
  18. 监控系统相关的常见面试问题
  19. Resources的使用方式
  20. TLS certificate verification has been disabled!

热门文章

  1. 史上最严数据保护条例欧盟GDPR今日生效,你可能需要这版中文全文(下)
  2. 配置路由器用SSH登陆
  3. Java的学习道路(一)
  4. element-ui中el-dialog使用技巧
  5. Python中文件路径
  6. 关于短视频技术轮廓探讨
  7. DRIVER_UNLOADED_WITHOUT_CANCELLING_PENDING_OPERATION error
  8. python 修改图片尺寸_用Python更改图片尺寸大小
  9. obj 与 fbx 三维模型文件对比
  10. 大数相乘 (模板)