2010 SD - ICPC D - Emergency
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
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 ;
}
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
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的更多相关文章
- LInux 安全测试 2
Centos/CentOS 6.4 linux内核2.6.3.2本地提权exp代码 jincon 发表于 2014-05-31 08:25:00 发表在: 代码审计 最近我接手的一台centos 服务 ...
- LInux 安全测试
[CVE-2013-2094]Linux PREF_EVENTS Local Root 2.6.37-3.8.10 x86_64 踩(0)http://zone.wooyun.org/content/ ...
- 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 ...
- 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 ...
- ICPC 2018 亚洲横滨赛 C Emergency Evacuation(暴力,贪心)
ICPC 2018 亚洲横滨赛 C Emergency Evacuation 题目大意 你一个车厢和一些人,这些人都坐在座位上,求这些人全部出去的时间最小值 Solution 题目咋说就咋做 直接模拟 ...
- 代码对齐 (Alignment of Code,ACM/ICPC NEERC 2010,UVa1593)
题目描述: 解题思路: 输入时提出单个字符串,并用一个数组记录每列最长长度,格式化输出 #include <iostream> #include <algorithm> #in ...
- UVALive - 4787 ICPC WF 2010 Tracking Bio-bots【dp】
UVa 4787 WF题果然不一样,本来想暴力搜索,数据太大了,数组都开不了.看题解也不太懂,记录一下书上的题解,以后再看: 此题是给出N*M的格子,有些地方是墙,不可走.求所有不能只通过向上或者向右 ...
- WinCE下读取注册表获得SD路径
WinCE下读取注册表获得SD路径 [要点]WinCE注册表中[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\SDMemory\] 下键Folde ...
- 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 ...
随机推荐
- socketserver + ftp
--------------------------------------------生活不止眼前的苟且,还有诗和远方的田野. day 29 socketserver + ftp # # ----- ...
- nginx负载均衡精简配置实例
[root@localhost ~]# vim nginx.conf user nginx; worker_processes ; error_log /var/log/nginx/error.log ...
- koa入门
创建koa2工程 首先初始化项目 npm init -y 项目名称 安装koa $ npm i koa 我们创建一个目录hello-koa并作为工程目录用VS Code打开.然后,我们创建app.js ...
- 后台管理系统之邮件开发(Java实现)
一,功能点 后台管理系统,添加用户时.对注册的新用户邮箱发送初始密码. 二,代码实现 1.Mail实体类 public class Mail { private Set<String> r ...
- Javascript与C#对变量的处理方式
先来看一下Javascript的情况(下面所说的基本类型和简单类型是一个意思): Javascript中变量会存在两种情况,一种是基本类型的,一共有五种,有null.Bollean.undefin ...
- MySQL经典编程问题
星期数的问题 1 计算日期是周几 这个问题看似很简单,可以用MySQL内置函数来计算 (1) weekday(date)其返回值是0-6,0代表Monday, 6代表Sunday: (2) dayof ...
- java lang(Comparable接口) 和java util(Comparator接口)分析比较
//Comparable 接口强行对实现它的每个类的对象进行整体排序. -- 自然排序.类的compareTo称为自然比较方法. public interface Comparable<T> ...
- 剑指offer(14)
题目: 操作给定的二叉树,将其变换为源二叉树的镜像. 思路: 这里有个细节,我们发现,6节点的子节点在操作之后并没有发生变化,所以等会我们在交换的时候,交换的不是节点的数值,而是整个节点. 另外我们进 ...
- html5调用手机摄像头(图片可多选 限pc)
html5自带的 input file=”” ,纯html5,并且不涉及到js ,就可以实现.代码如下: <input type="file" accept="im ...
- Object.defineProperties()与Proxy对象代理
Object.defineProperties() 了不起啊..vue.js通过它实现双向绑定的 Object.defineProperties(obj,props) 方法直接在一个对象上定义新的属性 ...