PivotOJ

Inside information

시간 제한: 2000ms메모리 제한: 512MB출처: BOI 2021BOJ 21846

문제

Why did nobody tell you that computer science books can be so boring?! You really do not make progress with them, and your BOI medal is getting out of reach. But wait—who says you have to win it fair and square?*

BOI officials already mentioned that task statements are kept in a secret vault that can only be opened by the chair of the Scientific Committee. So the statements are beyond your reach. However, getting access to test data beforehand sounds manageable and should be enough to give you an advantage.

Unfortunately for you, the Scientific Committee has taken measures against possible unfairness. They split up the test data into NN chunks and distributed them among NN servers numbered from 1 to NN. Initially, server ii holds data chunk ii. The NN servers are connected by N1N - 1 wires in such a way that any two servers are connected to each other either directly or indirectly. From time to time, two servers share their data, meaning that afterwards both store the same chunks of data, namely precisely those chunks that were stored by at least one of them before. Any two servers directly connected to each other, and only these servers, share their data precisely once.

You are given the whole sequence of share operations. To coordinate your hacking attempts, you want to know at several points, in between two share operations, how test data is currently distributed among the servers. More precisely, you query whether a given server currently stores a given data chunk or how many servers currently store a given data chunk.

Write a program that allows you to answer such questions given (a) the sequence of share operations and (b) when each query is made.

* Well, we do, and your team leaders do too, but never mind.

입력

The input describes the sequence of share operations and queries. The first line of input contains two integers NN and KK. Each of the following N+K1N + K - 1 lines can have one of the following forms and meanings:

  • "S aa bb" means servers aa and bb Share all their data.
  • "Q aa dd" means you Query whether server aa currently stores data chunk dd.
  • "C dd" means you query the Count (number) of servers that currently store data chunk dd.

N1N - 1 lines start with an S, and KK lines start with either Q or C.

출력

For each query "Q aa dd" in the input, your program should output a single line containing the string yes if the aa-th server stored the dd-th piece of data at the time of the query, or no otherwise. For each query "C dd" your program should output a single line containing a single integer: the number of servers storing data chunk dd at the time of the query. Of course, the answer to each query only depends on the share operations that happened before the query.

예제

예제 1

입력
6 9
S 1 2
S 1 3
S 3 4
Q 5 1
S 4 5
S 1 6
Q 5 1
Q 1 5
C 1
C 2
C 3
C 4
C 5
C 6
출력
no
yes
no
6
6
5
3
2
2

예제 2

입력
4 4
S 1 2
S 1 3
S 3 4
Q 2 1
Q 2 2
Q 2 3
Q 2 4
출력
yes
yes
no
no
코드를 제출하려면 로그인하세요.