D - Emergency

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

 use MathJax to parse formulas

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 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

Sample Output

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

Hint

明显就是一个floyd变形

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0xfffffff;
int n, m, q;
bool vis2[maxn], G[][];
int d[][]; void floyd(int k) //更新与点k相关联的所有的距离
{
for(int i = ; i < n; i++)
for(int j = ; j < n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
int main()
{
int kase = ;
while(scanf("%d%d%d", &n, &m, &q))
{ for(int i = ; i < n; i++)
for(int j = i + ; j < n; j++)
d[i][i] = , d[i][j] = d[j][i] = INF;
if(n == && m == && q == ) break;
mem(vis2, );
int u, v, w;
for(int i = ; i < m; i++)
{
rd(u), rd(v), rd(w);
d[u][v] = min(d[u][v], w);
}
printf("Case %d:\n", ++kase); int o, x;
for(int i = ; i < q; i++)
{
rd(o);
if(o == )
{
rd(x);
if(!vis2[x]) floyd(x);
if(vis2[x]) printf("City %d is already recaptured.\n", x);
vis2[x] = ; }
else if(o == )
{
rd(u), rd(v);
if(vis2[u] == || vis2[v] == )
printf("City %d or %d is not available.\n", u, v);
else if(d[u][v] == INF) printf("No such path.\n");
else
{
printf("%d\n", d[u][v]); } } } printf("\n"); } return ;
}
D - Emergency

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

 use MathJax to parse formulas

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 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

Sample Output

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

Hint

2010 SD - ICPC D - Emergency的更多相关文章

  1. LInux 安全测试 2

    Centos/CentOS 6.4 linux内核2.6.3.2本地提权exp代码 jincon 发表于 2014-05-31 08:25:00 发表在: 代码审计 最近我接手的一台centos 服务 ...

  2. LInux 安全测试

    [CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...

  3. linux 2.6.37-3.x.x x86_64

    /* * linux 2.6.37-3.x.x x86_64, ~100 LOC * gcc-4.6 -O2 semtex.c && ./a.out * 2010 sd@fuckshe ...

  4. ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010

    ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...

  5. ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)

    ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 ...

  6. 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)

    题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...

  7. UVALive - 4787 ICPC WF 2010 Tracking Bio-bots【dp】

    UVa 4787 WF题果然不一样,本来想暴力搜索,数据太大了,数组都开不了.看题解也不太懂,记录一下书上的题解,以后再看: 此题是给出N*M的格子,有些地方是墙,不可走.求所有不能只通过向上或者向右 ...

  8. WinCE下读取注册表获得SD路径

    WinCE下读取注册表获得SD路径 [要点]WinCE注册表中[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory\] 下键Folde ...

  9. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?

    I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...

随机推荐

  1. sczd

  2. 第十二届湖南省赛 (B - 有向无环图 )(拓扑排序+思维)好题

    Bobo 有一个 n 个点,m 条边的有向无环图(即对于任意点 v,不存在从点 v 开始.点 v 结束的路径). 为了方便,点用 1,2,…,n 编号. 设 count(x,y) 表示点 x 到点 y ...

  3. CentOS 7.2 yum安装LAMP环境

    https://www.linuxidc.com/Linux/2016-11/136766.htm 详见以上链接,用yum安装方便省事. 尤其注意,mysql数据要设置远程连接.

  4. virtualization - Ubuntu Budgie screen distortion in Hyper-V - Ask Ubuntu

    virtualization - Ubuntu Budgie screen distortion in Hyper-V - Ask Ubuntuhttps://askubuntu.com/questi ...

  5. HTML中的几种空格

    HTML提供了5种空格实体(space entity),它们拥有不同的宽度,非断行空格( )是常规空格的宽度,可运行于所有主流浏览器.其他几种空格(       ‌‍)在不同浏览器中宽度各异.     ...

  6. [GS]uuid-ossp

    uuid-ossp 原贴地址:http://postgres.cn/docs/9.6/uuid-ossp.html 关于 OSSP的含义 uuid-ossp模块提供函数使用几种标准算法之一产生通用唯一 ...

  7. Collections斗地主案例

    package com.zhangxueliang.doudizhu; import java.util.ArrayList; import java.util.Collections; public ...

  8. 前端开发之css

    <!--页面中的组成部分通常随便打开一个网页,有文字,图片,视频,表格,音频,表单(注册信息) css 属性/尺寸/边框/背景 1.css的尺寸属性,就是大小width max-width mi ...

  9. python之路--网络通信协议

    一 . osi七层协议 互联网协议按照功能不同分为osi七层或tcp/ip五层或tcp/ip四层 二 . tcp三次握手和四次挥手 我们知道网络层,可以实现两个主机之间的通信.但是这并不具体,因为,真 ...

  10. SCP传送文件时提示No ECDSA host key is known forx.x.x.x and you have requested strict checking.问题的解决办法

    在使用SCP向其他设备传送文件时,打印如下错误: No ECDSA host key is known for x.x.x.x and you have requested strict checki ...