QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#18815. 트리와 쿼리 12

统计

$N$개의 정점으로 이루어진 루트없는 트리의 포레스트 $F$가 있다. 가장 처음에 $F$에 속하는 모든 트리는 정점 하나로만 이루어져 있는 트리이다. 아래와 같은 쿼리를 수행해보자.

  • 1 A B: 정점 $A$와 $B$를 연결하는 간선을 추가한다. 쿼리가 주어지기 전에 $A$와 $B$사이에는 간선이 없다.
  • 2 A B: 정점 $A$와 $B$를 연결하는 간선을 제거한다. 쿼리가 주어지기 전에 $A$와 $B$사이에는 간선이 있다.
  • 3 A B: 정점 $A$에서 $B$로 가는 경로가 있는지 없는지 조사한다. 있는 경우에는 $1$, 없는 경우에는 $0$을 출력한다.

모든 $A$와 $B$는 $1 \le A, B \le N$, $A \ne B$를 만족하고, 모든 간선은 방향이 없다.

입력

첫째 줄에 정점의 개수 $N$($2 \le N \le 100{,}000$)과 쿼리의 개수 $M$($1 \le M \le 100{,}000$)이 주어진다. 둘째 줄부터 $M$개의 줄에 쿼리가 한 줄에 하나씩 주어진다. 쿼리의 수행 결과가 포레스트인 입력만 주어진다.

출력

3번 쿼리의 결과를 한 줄에 하나씩 출력한다.

Sample

Input

5 11
3 1 5
1 1 2
1 1 3
1 3 4
1 5 4
3 1 5
2 4 5
3 1 5
2 3 4
1 3 5
3 1 5

Output

0
1
0
1

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.