P26996 [AtCoder] Propagating Edges
提高
题目描述

Problem Description

You are given an undirected graph with $ N $ vertices and $ 0 $ edges. Process $ Q $ queries as follows:

  • add query ($type\ =\ 1,\ u,\ v$): If there is no edge between $ u $ and $ v $, add an edge between them.
  • complete query ($type\ =\ 2,\ u,\ v\ =\ 0$): For all pairs of vertices $a,\ b$, if $u,\ a,\ b$ are all connected and there is no edge between $ a $ and $ b $, add an edge between $ a $ and $ b $.
  • check query ($type\ =\ 3,\ u,\ v$): Given $ u $ and $ v $. If there is a direct edge between $ u $ and $ v $, output Yes; otherwise, output No.

Input Format

The input is given from the standard input in the following format:

$ N $ $ Q $ $ type_1 $ $ u_1 $ $ v_1 $ $ type_2 $ $ u_2 $ $ v_2 $ $ : $ $ type_Q $ $ u_Q $ $ v_Q $

Output Format

For each check query, output Yes or No.

Sample Input and Output

Sample Input #1

3 6
1 1 2
1 2 3
3 1 2
3 1 3
2 1 0
3 1 3

Sample Output #1

Yes
No
Yes

Sample Input #2

3 6
2 3 0
3 1 3
1 3 1
2 3 0
1 1 2
3 2 1

Sample Output #2

No
Yes

Sample Input #3

8 20
1 3 6
2 6 0
2 2 0
2 7 0
1 7 3
3 2 6
1 4 2
3 3 7
1 2 6
2 4 0
2 2 0
3 3 1
2 8 0
2 8 0
1 8 2
2 7 0
3 5 4
1 4 2
3 5 7
3 2 3

Sample Output #3

No
Yes
No
No
No
Yes

Notes/Hints

Constraints

  • $2\ \leq\ N\ \leq\ 100,000$
  • $1\ \leq\ Q\ \leq\ 200,000$
  • $type_i\ =\ 1,\ 2,\ 3$
  • $1\ \leq\ u_i\ \leq\ N$
  • For add and check queries, $1\ \leq\ v_i\ \leq\ N$ and $u_i\ \neq\ v_i$
  • For complete queries, $v_i\ =\ 0$
  • All input values are integers.

Sample Explanation 1

Edges are added between $(1,\ 2)$ and $(2,\ 3)$ by the 1st and 2nd queries. Then, an edge is added between $(1,\ 3)$ by the 5th query.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 6 1 1 2 1 2 3 3 1 2 3 1 3 2 1 0 3 1 3
样例输出
Yes No Yes