QOJ.ac

QOJ

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

#18814. Tree and Query 11

الإحصائيات

There are $N$ rooted trees each consisting of a single vertex. The vertices are numbered from $1$ to $N$.

Write a program that performs the following queries:

  • 1 u v: Add an edge between u and v. Here, v becomes the parent of u. Before the query is executed, u is the root of the tree containing u, and it is guaranteed that u and v belong to different trees.
  • 2 v: Cut the edge connecting v and its parent. v is not the root.
  • 3 u v: Print the LCA of u and v. u and v are in the same tree.

Input

The first line contains $N$ ($2 \le N \le 100{,}000$) and the number of queries $M$ ($1 \le M \le 200{,}000$).

The next $M$ lines each contain one query.

Output

For each type 3 query, print the result in order, one per line.

Examples

Input 1

5 9
3 1 1
1 1 2
1 3 2
1 4 3
3 1 4
3 3 4
2 4
1 5 3
3 1 5

Output 1

1
2
3
2

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.