Processing math: 100%
Component sum - MarisaOJ: Marisa Online Judge

Component sum

Time limit: 1000 ms
Memory limit: 256 MB
Given a graph of n vertices and no edge. There are q queries of either form: - 1uv add an edge between u and v. - 2u calculate the sum of the vertices in the connected component to which u belongs. ### Input - The first line contains 2 integers n,q. - The next q lines, each line is a query. For the 1 query, the line contains 3 integers 1,u,v, and for the 2 query, the line contains 2 integers 2,u. ### Output - For each query of type 2, print on one line a single integer that is the sum of the vertices in the component to which u belongs. ### Constraints - 1≤n,q≤105. - 1≤u,v≤n. ### Example Input: 651121132215624 Output: 64