#t529. 亲戚2
亲戚2
Relatives 2
Problem Background
Special for beginners, ^_^
Problem Description
If a family is too large, it is indeed not easy to tell whether two people are relatives. Now given a certain relatives graph, find the number of people in the family of any given person.
The rule is: if and are relatives, and and are relatives, then and are also relatives. If are relatives, then all of 's relatives are also 's relatives, and all of 's relatives are also 's relatives.
Input Format
The first line: three integers (, ), representing people and pieces of information.
The following lines: each piece of information is in one of two forms:
M a b: means and are relatives.Q a: requires outputting the number of people in the family of .
Output Format
Output the number of people in the family of .
Sample Input
5 10
M 3 2
Q 4
M 1 2
Q 4
M 3 2
Q 1
M 3 1
Q 5
M 4 2
Q 4
Sample Output
1
1
3
1
4
Constraints
Time limit: 1s; memory limit: 1024 KiB for each test case.