Problem5350--CF EDU - DSU - Step 1 - C. Experience

5350: CF EDU - DSU - Step 1 - C. Experience

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

In a novel online game, the players fight the monsters and get the experience, as usual. To fight monsters players join together in raid teams. After the destruction of the monster, all the players of the team get the same amount of experience points. The special feature of the game is that a team cannot be split up and no one can leave a team. The only supported operation is to join two teams together.
Since there are already a lot of people playing the game, you are asked to maintain the experience points of the players.

Input

The first line of the input contains two integers $n,\ m\ (1 ≤ n, m ≤ 2·10^5)$ — the number of players and the number of queries.
Next $m$ lines contain the description of queries, one per line. A query can be of three types:
  •     join X Y — join two teams to which players $X$ and $Y$ belong to (if they are already in the same team, nothing changes).
  •     add X V — add $V\ (1 ≤ V ≤ 100)$ experience points to each player in a team to which player $X$ belongs to.
  •     get X — output the current number of experience points of player $X$.
Initially, each player has $0$ experience points and each of the player is in its own team of size one.

Output

For each query get X output the current number of experience points of player $X$ on a separate line.

Sample 1 Input

3 6
add 1 100
join 1 3
add 1 50
get 1
get 2
get 3

Sample 1 Output

150
0
50

HINT

题目来源:CodeForces EDU

Source/Category

数据结构 2.51.并查集