102782: [AtCoder]ABC278 C - FF

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:5 Solved:0

Description

Score : $300$ points

Problem Statement

Takahashi runs an SNS "Twidai," which has $N$ users from user $1$ through user $N$. In Twidai, users can follow or unfollow other users.

$Q$ operations have been performed since Twidai was launched. The $i$-th $(1\leq i\leq Q)$ operation is represented by three integers $T_i$, $A_i$, and $B_i$, whose meanings are as follows:

  • If $T_i = 1$: it means that user $A_i$ follows user $B_i$. If user $A_i$ is already following user $B_i$ at the time of this operation, it does not make any change.
  • If $T_i = 2$: it means that user $A_i$ unfollows user $B_i$. If user $A_i$ is not following user $B_i$ at the time of this operation, it does not make any change.
  • If $T_i = 3$: it means that you are asked to determine if users $A_i$ and $B_i$ are following each other. You need to print Yes if user $A_i$ is following user $B_i$ and user $B_i$ is following user $A_i$, and No otherwise.

When the service was launched, no users were following any users.

Print the correct answers for all operations such that $T_i = 3$ in ascending order of $i$.

Constraints

  • $2 \leq N \leq 10 ^ 9$
  • $1 \leq Q \leq 2\times10 ^ 5$
  • $T _ i=1,2,3\ (1\leq i\leq Q)$
  • $1 \leq A _ i \leq N\ (1\leq i\leq Q)$
  • $1 \leq B _ i \leq N\ (1\leq i\leq Q)$
  • $A _ i\neq B _ i\ (1\leq i\leq Q)$
  • There exists $i\ (1\leq i\leq Q)$ such that $T _ i=3$.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

$N$ $Q$
$T _ 1$ $A _ 1$ $B _ 1$
$T _ 2$ $A _ 2$ $B _ 2$
$\vdots$
$T _ Q$ $A _ Q$ $B _ Q$

Output

Print $X$ lines, where $X$ is the number of $i$'s $(1\leq i\leq Q)$ such that $T _ i=3$. The $j$-th $(1\leq j\leq X)$ line should contain the answer to the $j$-th operation such that $T _ i=3$.


Sample Input 1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

Sample Output 1

No
Yes
No
No

Twidai has three users. The nine operations are as follows.

  • User $1$ follows user $2$. No other users are following or followed by any users.
  • Determine if users $1$ and $2$ are following each other. User $1$ is following user $2$, but user $2$ is not following user $1$, so No is the correct answer to this operation.
  • User $2$ follows user $1$.
  • Determine if users $1$ and $2$ are following each other. User $1$ is following user $2$, and user $2$ is following user $1$, so Yes is the correct answer to this operation.
  • User $2$ follows user $3$.
  • User $3$ follows user $2$.
  • Determine if users $1$ and $3$ are following each other. User $1$ is not following user $3$, and user $3$ is not following user $1$, so No is the correct answer to this operation.
  • User $1$ unfollows user $2$.
  • Determine if users $1$ and $2$ are following each other. User $2$ is following user $1$, but user $1$ is not following user $2$, so No is the correct answer to this operation.

Sample Input 2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

Sample Output 2

Yes
No

A user may follow the same user multiple times.


Sample Input 3

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

Sample Output 3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes

Input

题意翻译

【题目翻译】 洛谷是一个大平台,从前,这里有 $n$ 个用户。刚开始,他们没有任何关系。 有 $q$ 次操作,每组操作包含 $op_i$,$a_i$,$b_i$: + $op_i = 1$,表示 $a_i$ 关注了 $b_i$。 + $op_i = 2$,表示 $a_i$ 取关了 $b_i$。 + $op_i = 3$,表示查询 $a_i$ 与 $b_i$ 是否互关。 对于每个 $op_i = 3$,输出结果。 translated by @[liangbowen](https://www.luogu.com.cn/user/367488). 【输入格式】 第一行两个数 $n$,$q$。 接下来 $q$ 行,每行三个数 $op_i$,$a_i$,$b_i$。 【输出格式】 对于每个 $op_i = 3$,输出结果。 【数据范围】 $1 \le n \le 10^9$ $1 \le q \le 2 \times 10^5$ 保证 $1 \le a_i, b_i \le n$,且 $a_i \ne b_i$。 保证 $op_i \in \{1, 2, 3\}$。

Output

得分:300分

问题描述

Takahashi 运营着一个名为“Twidai”的社交网络,拥有从用户1到用户N的N个用户。 在Twidai中,用户可以关注或取消关注其他用户。

自Twidai推出以来,已经执行了Q次操作。 第i次$(1≤i≤Q)$操作由三个整数$T_i$,$A_i$和$B_i$表示,其含义如下:

  • 如果$T_i = 1$:表示用户$A_i$关注用户$B_i$。如果在执行此操作时用户$A_i$已经关注了用户$B_i$,则不会产生任何变化。
  • 如果$T_i = 2$:表示用户$A_i$取消关注用户$B_i$。如果在执行此操作时用户$A_i$没有关注用户$B_i$,则不会产生任何变化。
  • 如果$T_i = 3$:表示要求你判断用户$A_i$和$B_i$是否互相关注。如果用户$A_i$关注用户$B_i$且用户$B_i$关注用户$A_i$,则你需要打印Yes,否则打印No

服务推出时,没有用户关注任何用户。

按照$i$升序打印所有$T_i = 3$的操作的正确答案。

约束

  • $2 ≤ N ≤ 10 ^ 9$
  • $1 ≤ Q ≤ 2\times10 ^ 5$
  • $T _ i=1,2,3\ (1≤i≤Q)$
  • $1 ≤ A _ i ≤ N\ (1≤i≤Q)$
  • $1 ≤ B _ i ≤ N\ (1≤i≤Q)$
  • $A _ i\neq B _ i\ (1≤i≤Q)$
  • 存在$i\ (1≤i≤Q)$使得$T _ i=3$。
  • 输入中的所有值都是整数。

输入

输入将从标准输入以以下格式给出:

$N$ $Q$
$T _ 1$ $A _ 1$ $B _ 1$
$T _ 2$ $A _ 2$ $B _ 2$
$\vdots$
$T _ Q$ $A _ Q$ $B _ Q$

输出

打印X行,其中X是满足$T _ i=3$的i的数量。 第j行$(1≤j≤X)$应该包含满足$T _ i=3$的第j个操作的答案。


样例输入1

3 9
1 1 2
3 1 2
1 2 1
3 1 2
1 2 3
1 3 2
3 1 3
2 1 2
3 1 2

样例输出1

No
Yes
No
No

Twidai有三个用户。 九次操作如下。

  • 用户1关注用户2。没有其他用户关注或被任何用户关注。
  • 判断用户1和2是否互相关注。用户1关注用户2,但用户2不关注用户1,因此此操作的正确答案是No
  • 用户2关注用户1。
  • 判断用户1和2是否互相关注。用户1关注用户2,用户2关注用户1,因此此操作的正确答案是Yes
  • 用户2关注用户3。
  • 用户3关注用户2。
  • 判断用户1和3是否互相关注。用户1不关注用户3,用户3不关注用户1,因此此操作的正确答案是No
  • 用户1取消关注用户2。
  • 判断用户1和2是否互相关注。用户2关注用户1,但用户1不关注用户2,因此此操作的正确答案是No

样例输入2

2 8
1 1 2
1 2 1
3 1 2
1 1 2
1 1 2
1 1 2
2 1 2
3 1 2

样例输出2

Yes
No

一个用户可以多次关注同一个用户。


样例输入3

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

样例输出3

No
No
No
No
Yes
Yes
No
No
No
Yes
Yes

加入题单

上一题 下一题 算法标签: