CF864F.Cities Excursions
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n cities in Berland. Some pairs of them are connected with m directed roads. One can use only these roads to move from one city to another. There are no roads that connect a city to itself. For each pair of cities (x, y) there is at most one road from x to y.
A path from city s to city t is a sequence of cities _p_1, _p_2, ... , p__k, where _p_1 = s, p__k = t, and there is a road from city p__i to city p__i + 1 for each i from 1 to k - 1. The path can pass multiple times through each city except t. It can't pass through t more than once.
A path p from s to t is ideal if it is the lexicographically minimal such path. In other words, p is ideal path from s to t if for any other path q from s to t p__i < q__i, where i is the minimum integer such that p__i ≠ q__i.
There is a tourist agency in the country that offers q unusual excursions: the j-th excursion starts at city s__j and ends in city t__j.
For each pair s__j, t__j help the agency to study the ideal path from s__j to t__j. Note that it is possible that there is no ideal path from s__j to t__j. This is possible due to two reasons:
- there is no path from s__j to t__j;
- there are paths from s__j to t__j, but for every such path p there is another path q from s__j to t__j, such that p__i > q__i, where i is the minimum integer for which p__i ≠ q__i.
The agency would like to know for the ideal path from s__j to t__j the k__j-th city in that path (on the way from s__j to t__j).
For each triple s__j, t__j, k__j (1 ≤ j ≤ q) find if there is an ideal path from s__j to t__j and print the k__j-th city in that path, if there is any.
伯兰德有 n 座城市。其中某些城市对之间由 m 条有向道路连接。人们只能通过这些道路在城市间移动。不存在连接某城市到其自身的道路。对于任意一对城市 (x,y),至多只存在一条从 x 到 y 的道路。
从城市 s 到城市 t 的一条路径是一个城市序列 p1,p2,…,pk,满足 p1=s、pk=t,且对每个 i=1,2,…,k−1,均存在一条从城市 pi 到城市 pi+1 的道路。该路径可多次经过除 t 外的任意城市,但不能多次经过 t(即 t 在路径中至多出现一次)。
从 s 到 t 的路径 p 被称为理想路径,当且仅当它是所有从 s 到 t 的路径中字典序最小者。换言之,若 p 是从 s 到 t 的理想路径,则对任意另一条从 s 到 t 的路径 q,设 i 是满足 pi=qi 的最小下标,则必有 pi<qi。
该国有一家旅游机构,提供 q 种特殊游览路线:第 j 种游览路线起始于城市 sj,终止于城市 tj。
对每一对 (sj,tj),请协助该机构找出从 sj 到 tj 的理想路径。注意:从 sj 到 tj 可能不存在理想路径,原因如下两种之一:
- 不存在从 sj 到 tj 的路径;
- 存在从 sj 到 tj 的路径,但对任意一条这样的路径 p,总存在另一条从 sj 到 tj 的路径 q,使得 pi>qi,其中 i 是满足 pi=qi 的最小下标。
该机构希望知道:在从 sj 到 tj 的理想路径中(若存在),第 kj 个城市是哪一个(按从 sj 到 tj 的顺序计数)。
对每个三元组 (sj,tj,kj)(其中 1≤j≤q),请判断是否存在从 sj 到 tj 的理想路径;若存在,则输出该路径中第 kj 个城市;否则不输出任何内容。
输入格式
The first line contains three integers n, m and q (2 ≤ n ≤ 3000,0 ≤ m ≤ 3000, 1 ≤ q ≤ 4·105) — the number of cities, the number of roads and the number of excursions.
Each of the next m lines contains two integers x__i and y__i (1 ≤ x__i, y__i ≤ n, x__i ≠ y__i), denoting that the i-th road goes from city x__i to city y__i. All roads are one-directional. There can't be more than one road in each direction between two cities.
Each of the next q lines contains three integers s__j, t__j and k__j (1 ≤ s__j, t__j ≤ n, s__j ≠ t__j, 1 ≤ k__j ≤ 3000).
第一行包含三个整数 n、m 和 q(2 ≤ n ≤ 3000,0 ≤ m ≤ 3000,1 ≤ q ≤ 4⋅105)——分别表示城市的数量、道路的数量以及远足活动的数量。
接下来的 m 行中,每行包含两个整数 xi 和 yi(1 ≤ xi, yi ≤ n,xi = yi),表示第 i 条道路从城市 xi 指向城市 yi。所有道路均为单向。任意两个城市之间在每个方向上至多只有一条道路。
接下来的 q 行中,每行包含三个整数 sj、tj 和 kj(1 ≤ sj, tj ≤ n,sj = tj,1 ≤ kj ≤ 3000)。
输出格式
In the j-th line print the city that is the k__j-th in the ideal path from s__j to t__j. If there is no ideal path from s__j to t__j, or the integer k__j is greater than the length of this path, print the string '-1' (without quotes) in the j-th line.
在第 j 行输出从 sj 到 tj 的理想路径中第 kj 个城市。若从 sj 到 tj 不存在理想路径,或整数 kj 大于该路径的长度,则在第 j 行输出字符串 -1(不带引号)。
输入输出样例
输入#1
7 7 5 1 2 2 3 1 3 3 4 4 5 5 3 4 6 1 4 2 2 6 1 1 7 3 1 3 2 1 3 5
输出#1
2 -1 -1 2 -1
输入解题思路,AI测评打分。不知道怎么写?