|시간 제한||메모리 제한||제출||정답||맞힌 사람||정답 비율|
|4 초||537 MB||39||31||29||82.857%|
There are N cities and M roads in Ibaraki Prefecture, Japan. Cities are numbered from 0 through N - 1 in the increasing order of their population. Each road connects a pair of distinct cities, and can be traveled in both directions. You can travel from any city to any other city by using one or more of these roads.
You planned Q trips, numbered from 0 through Q - 1. The trip i (0 ≤ i ≤ Q - 1) is to travel from the city Si to the city Ei.
You are a werewolf. You have two forms: human form and wolf form. At the beginning of each trip you are in human form. At the end of each trip, you must be in wolf form. During the trip you have to transform (change from human form to wolf form) exactly once. You can transform only when you are in some city (possibly Si or Ei).
Living as a werewolf is not easy. You must avoid low-populated cities when you are in human form, and avoid highly-populated cities when you are in wolf form. For each trip i (0 ≤ i ≤ Q - 1), there are two thresholds Li and Ri (0 ≤ Li ≤ Ri ≤ N - 1) that indicate which cities must be avoided. More specifically, you must avoid the cities 0, 1, ..., Li - 1 when you are in human form, and must avoid the cities Ri + 1, Ri + 2, ..., N - 1 when you are in wolf form. This means in the trip i, you can only transform in one of the cities Li, Li + 1, ..., Ri.
Your task is to determine, for each trip, whether it is possible to travel from the city Si to the city Ei in a way that satisfies the aforementioned constraints. The route you take can have an arbitrary length.
You should implement the following function:
int check_validity(int N, int X, int Y, int S, int E, int L, int R)
N: the number of cities.
Y: arrays of length M. For each j (0 ≤ j ≤ M - 1), the city
X[j]is directly connected to the city
X[j]by a road.
R: arrays of length Q, representing the trips.
Note that the values of M and Q are the lengths of the arrays, and can be obtained as indicated in the implementation notice.
check_validity is called exactly once for each test case. This function should return an array A of integers of length Q. The value of Ai (0 ≤ i ≤ Q - 1) must be
1 if the trip i is possible while satisfying the aforementioned conditions, or
Let N = 6, M = 6, Q = 3, X = [5, 1, 1, 3, 3, 5], Y = [1, 2, 3, 4, 0, 2], S = [4, 4, 5], E = [2, 2, 4], L = [1, 2, 3], and R = [2, 2, 4].
The grader calls
check_validity(6, [5, 1, 1, 3, 3, 5], [1, 2, 3, 4, 0, 2], [4, 4, 5], [2, 2, 4], [1, 2, 3], [2, 2, 4]).
For the trip 0, you can travel from the city 4 to the city 2 as follows:
For the trips 1 and 2, you cannot travel between the given cities.
Hence, your program should return [1, 0, 0].
N ≤ 100, M ≤ 200, Q ≤ 100
N ≤ 3,000, M ≤ 6,000, Q ≤ 3,000
M = N - 1 and each city is incident to at most 2 roads (the cities are connected in a line)
No additional constraints
The sample grader reads the input in the following format:
The sample grader prints the return value of
check_validity in the following format:
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)