QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100

#16487. Key Point

Statistics

题目描述

给定一个包含 $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.