题目描述

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

样例输出

Case 1:
City 0 or 2 is not available.
3
No such path.
City 2 is already recaptured.
 /*
问题
输入顶点数n,路径数m和操作次数q
如果操作数是0,x如果没有被收回时,输出City %d is already recaptured.
如果操作数是1,x和y如果有一个没有被收回,输出City x or y is not available.
如果存在最短路径输出最短路径,不存在路径输出No such path. 解题思路
由于询问次数可能很多和可能重复而且是任意两点间的最短路,所以每次加入一个点时进行一次Floyd,输出相应的结果即可。
*/
#include<cstdio>
#include<cstring>
const int INF=;
int n,m,q;
int e[][],book[];
void floyd(int x){
int i,j;
for(i=;i<n;i++){
for(j=;j<n;j++){
if(e[i][j] > e[i][x] + e[x][j]){
e[i][j] = e[i][x] + e[x][j];
}
}
}
/*for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%9d",e[i][j]);
}
printf("\n");
}*/
}
int main()
{
int u,v,w,op,x,y,i,j,t=;
while(scanf("%d%d%d",&n,&m,&q) == && n+m+q != ){
printf("Case %d:\n",t++); for(i=;i<n;i++){
for(j=;j<n;j++){
e[i][j] = i==j?:INF;
}
} while(m--){
scanf("%d%d%d",&u,&v,&w);
if(e[u][v] > w)
e[u][v] = w;
}
/*for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%9d",e[i][j]);
}
printf("\n");
}*/
memset(book,,sizeof(book));
while(q--){
scanf("%d",&op);
if(op == ){
scanf("%d",&x);
if(book[x])
printf("City %d is already recaptured.\n",x);
else{
floyd(x);
book[x]=;
}
}
else
{
scanf("%d%d",&x,&y);
if(book[x] == || book[y] == ){
printf("City %d or %d is not available.\n",x,y);
continue;
}
if(e[x][y] < INF)
printf("%d\n",e[x][y]);
else
printf("No such path.\n");
}
}
printf("\n");
}
return ;
}

Emergency(山东省第一届ACM程序设计真题+Floyd算法变型)的更多相关文章

  1. 2010山东省第一届ACM程序设计竞赛

    休眠了2月了 要振作起来了!!... http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2155 因 ...

  2. Shopping(山东省第一届ACM省赛)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  3. HDU 1874 畅通工程续(模板题——Floyd算法)

    题目: 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多.这让行人很困扰 ...

  4. POJ 1502 MPI Maelstrom(模板题——Floyd算法)

    题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...

  5. Emergency(山东省第一届ACM省赛)

    Emergency Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Kudo’s real name is not Kudo. H ...

  6. sdut 2159 Ivan comes again!(2010年山东省第一届ACM大学生程序设计竞赛) 线段树+离散

    先看看上一个题: 题目大意是: 矩阵中有N个被标记的元素,然后针对每一个被标记的元素e(x,y),你要在所有被标记的元素中找到一个元素E(X,Y),使得X>x并且Y>y,如果存在多个满足条 ...

  7. sdut 2153 Clockwise (2010年山东省第一届ACM大学生程序设计竞赛)

    题目大意: n个点,第i个点和第i+1个点可以构成向量,问最少删除多少个点可以让构成的向量顺时针旋转或者逆时针旋转. 分析: dp很好想,dp[j][i]表示以向量ji(第j个点到第i个点构成的向量) ...

  8. 2010年山东省第一届ACM大学生程序设计竞赛 Balloons (BFS)

    题意 : 找联通块的个数,Saya定义两个相连是 |xa-xb| + |ya-yb| ≤ 1 ,但是Kudo定义的相连是 |xa-xb|≤1 并且 |ya-yb|≤1.输出按照两种方式数的联通块的各数 ...

  9. Hello World! 2010年山东省第一届ACM大学生程序设计竞赛

    Hello World! Time Limit: 1000MS Memory limit: 65536K 题目描述 We know that Ivan gives Saya three problem ...

随机推荐

  1. [php-pear]如何使用 PHP-PEAR安装器,以及使用 PEAR 安装扩展库

    我们都知道 PHP PEAR,就是 PHP Extension and Application Respository,也就是 PHP 扩展和应用代码库. PHP 也可以通过 PEAR 安装器来进行 ...

  2. 完美融合 nextjs 和 antd

    相信大家在使用nextjs的时候,难免遇到一些坑.其实可能大部分原因在于 nextjs 做了很多封装,我们可能不能第一时间搞清楚包括它相关的所有配置,比如其中的webpack配置.我前面也写过 SSR ...

  3. 【Vue】浅谈Vue不同场景下组件间的数据交流

    浅谈Vue不同场景下组件间的数据“交流”   Vue的官方文档可以说是很详细了.在我看来,它和react等其他框架文档一样,讲述的方式的更多的是“方法论”,而不是“场景论”,这也就导致了:我们在阅读完 ...

  4. Python 关于 encode与decode 中文乱码问题

    字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(en ...

  5. git如何忽略已经加入版本控制的文件

    git移除已经追踪的文件 有时候新增一个文件,会自动追加到git的版本控制当中,但是又不想提交到仓库.可以按照下面的步骤: git status 查看管理状态: ml-py git:(master) ...

  6. MySQL 逻辑物理备份测试

    目录 逻辑备份 mysqldump 普通备份 mysqlpump 并行备份 mysqlpump 压缩并行备份 mydumper 并行备份 mydumper 并行压缩备份 小结 物理备份 xtrabac ...

  7. ping端口是否开放(windows,macos,linux)

    windows中ping端口:tcping命令 1. tcping 非自带命令,首先安装tcping命令,也可以去官网:http://www.elifulkerson.com/projects/tcp ...

  8. 人工智能-机器学习之seaborn(读取xlsx文件,小提琴图)

    我们不止可以读取数据库的内容,还可以读取xlsx文件的内容,这个库有在有些情况还是挺实用的 首先我们想读取这个文件的时候必须得现有个seaborn库 下载命令就是: pip install  seab ...

  9. flask_ Mongodb 的语法-排序

    MOngoDB的排序是挺有用的   ,跟MySQL有明显的区别 .. 它的原生语法的第一个参数为条件限定,第二个参数为排序字段 db.news.find({},{'_id':1})   #1是升序  ...

  10. 线性表java实现

    顺序表 public class SequenceList { /* * content,节点内容 * location,节点在表中的位置(序号) * */ private String conten ...