You are given \(n\ (0 \le n \le 500000)\) and \(q\ (1 \le q \le 600000)\) where \(n\) is a number of vertexes and \(q\) is a number of queries. Initially, you have a graph with no edges and 0 is written on every vertex, then you need to process \(q\) queries.
You have three types of queries:
- 1 type is to add an undirected edge between \(A \ and\ B\). \((1 \le A, B \le n)\)
The graph is guaranteed to be simple (without self-loops and multiple edges) even after adding edges. - 2 type is to add number B to every number written on vertexes with are in the same component with A. \((1 \le A \le n, 1 \le B \le 1000000)\)
- 3 type is to show the written number on A. \((1 \le A \le n)\)
Input format
- The first line contains an integer T (\(1 \le T \le 1000\)) representing the number of test cases that will follow.
- The first line of each test case contains two integers n and q.
- Next q lines in test case given queries in the following format:
Type of query if the type of query is 3 there given one integer A. Otherwise there given two integers \(A \ and\ B\).
Output format
For each query of 3 type, you should print answers on a different line.
3 1 1 3 1 2 5 2 1 1 3 1 1 1 2 3 1 3 2 4 12 2 3 226354 1 2 4 1 2 3 3 4 2 4 706744 3 2 2 2 402629 3 1 2 1 518322 1 2 4 3 3 3 4
0 1 1 0 0 706744 0 1335727 1109373
In first test case: 0 written on every vertex, so answer for vertex 1 is 0.
In second test case:
1st query, you add 1 to vertex 1 only.
2nd query. you print the written number on vertex 1, which is 1.
3rd query, you add edge between 1 and 2
4th query, you print the written number on vertex 1, which is 1.
5th query, you print the written number on vertex 2, which is 0.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor