No.1983 [Cherry 4th Tune C] Mermaid of the Southern Island
タグ : / 解いたユーザー数 58
作問者 : 👑
Kazun
/ テスター :
akakimidori
👑 Problem Statement
The Land of Zelkova is an island country consisting of $N$ islands. These $N$ islands are named island $1, \dots,$ island $N$.
Cherry-chan, a mermaid, can travel in both directions between island $a$ and island $b$ if and only if there exists an integer $i$ between $1$ and $M$, inclusive, such that $a=u_i, b=v_i$.
Cherry-chan, who easily gets lost, has decided to investigate for which pairs of a starting island and a destination island she is less likely to get lost.
Answer the following $Q$ questions. Here, the $q$-th question is given as a pair of integers $(x_q, y_q)$.
Question $q$
Does there exist exactly one sequence of integers $(p_0, p_1, \dots, p_k)$ satisfying all of the following conditions?
- $k \geq 1$
- $1 \leq p_i \leq N$
- $p_0=x_q, p_k=y_q$
- $p_0, p_1, \dots, p_k$ are all distinct.
- Cherry-chan can travel in both directions between island $p_{i-1}$ and island $p_i$.
Constraints
- $2 \leq N \leq 2 \times 10^5$
- $0 \leq M \leq \min(\frac{1}{2}N(N-1), 2 \times 10^5)$
- $1 \leq Q \leq 2 \times 10^5$
- $1 \leq u_i \leq N, 1 \leq v_i \leq N$
- $u_i \neq v_i$
- $i \neq j \Rightarrow (u_i, v_i) \neq (u_j, v_j), (u_i, v_i) \neq (v_j, u_j)$
- $1 \leq x_q \leq N, 1 \leq y_q \leq N$
- $x_q \neq y_q$
- All inputs are integers.
Input
$N$ $M$ $Q$ $u_1$ $v_1$ $\vdots$ $u_M$ $v_M$ $x_1$ $y_1$ $\vdots$ $x_Q$ $y_Q$
Output
The output consists of $Q$ lines. On the $q~(1 \leq q \leq Q)$-th line, print Yes if exactly one such sequence exists for question $q$, and No otherwise.
Do not forget the newline at the end.
Sample
Sample 1
Input
7 6 3 1 2 2 3 3 1 1 4 2 5 6 7 1 4 1 2 1 7
Output
Yes No No
Cherry-chan can travel between two islands connected by an arrow in the figure below.
- The $1$st question is $(x_1, y_1)=(1,4)$. Since $(1,4)$ is the only integer sequence satisfying the conditions, the answer is
Yes. - The $2$nd question is $(x_2, y_2)=(1,2)$. Since there exist two different integer sequences satisfying the conditions, $(1,2)$ and $(1,3,2)$, the answer is
No. - The $3$rd question is $(x_3 ,y_3)=(1,7)$. Since no integer sequence satisfying the conditions exists in the first place, the answer is
No.
Sample 2
Input
4 0 4 1 2 2 3 3 4 4 1
Output
No No No No
It is possible that Cherry-chan cannot travel between any islands.
Sample 2
Input
5 4 5 1 2 1 3 1 4 1 5 1 3 3 5 2 4 3 1 1 3
Output
Yes Yes Yes Yes Yes
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。