QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#16487. 關鍵點

الإحصائيات

給定一個包含 $n$ 個節點和 $\boldsymbol{n-1}$ 條有向邊的有向圖 $G$ 和一個不大於 $n$ 的正整數 $k$,保證圖 $G$ 中的所有邊在視為無向邊後圖連通(即形成一棵樹)。

現有 $q$ 次操作。操作共五種,參數分別如下:

  • 1 x y:翻轉節點 $x$ 和節點 $y$ 之間邊的方向,保證節點 $x$ 和節點 $y$ 之間存在一條邊;
  • 2 a:將節點 $a$ 的所有入邊翻轉方向;
  • 3 b:將節點 $b$ 的所有出邊翻轉方向;
  • 4 c:將節點 $c$ 的所有入邊和出邊翻轉方向;
  • 5 p:將 $k$ 的值修改為 $p$。

其中,節點 $u$ 的入邊表示以節點 $u$ 為終點的有向邊,節點 $u$ 的出邊表示以節點 $u$ 為起點的有向邊。

你需要維護這個有向圖,並在首次操作前和每次操作後,判斷是否所有除節點 $k$ 以外的節點都能透過目前的有向邊到達節點 $k$,若是則輸出 YES,否則輸出 NO。

輸入格式

第一行輸入三個整數 $n,k,q$($2 \le n \le 10^6$,$0 \le q \le 10^6$,$1 \le k \le n$)。

接下來 $n-1$ 行,每行輸入兩個正整數 $u_i,v_i$,表示節點 $u_i$ 和節點 $v_i$ 之間存在一條由節點 $u_i$ 至節點 $v_i$ 的有向邊($1 \le u_i,v_i \le n$)。

接下來 $q$ 行,每行輸入 $2\sim3$ 個正整數,表示一次操作,含義及格式見前面的題目敘述($1 \le x,y,a,b,c,p \le n$)。

保證圖 $G$ 中的所有邊在視為無向邊後圖連通(即形成一棵樹),保證在進行第一種操作時節點 $x$ 和節點 $y$ 之間存在一條邊。

輸出格式

共 $q+1$ 行,在首次操作前和每次操作後,判斷是否所有除節點 $k$ 以外的節點都能透過目前的有向邊到達節點 $k$,若是則輸出 YES,反之輸出 NO。

範例

輸入格式 1

10 10 10
9 10
1 5
3 9
8 9
4 9
7 9
5 4
2 10
6 7
4 5
3 2
3 1
1 10 2
1 5 1
1 4 5
5 4
2 9
1 9 3
2 9

輸出格式 1

YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO

輸入格式 2

10 4 10
8 9
2 4
10 5
9 4
3 2
1 2
5 4
6 4
7 8
1 2 1
1 2 1
5 10
1 5 4
1 10 5
3 4
1 5 4
5 2
1 5 10
1 4 5

輸出格式 2

YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.