#P8123. [BalticOI 2021] Inside information (Day1)
[BalticOI 2021] Inside information (Day1)
Description
There are servers. The -th server stores the -th data block at the beginning. Now there are several types of operations:
S a b: Server and server share data. That is, after the operation, both servers will contain the union of the data blocks originally held by these two servers, with duplicates removed (you can think of it as the union of data blocks).Q a d: Query whether server has data block .C a: Query the number of servers that store data block .
There are exactly S operations. If we treat each share as adding an edge, in the end these edges form a tree with the servers as nodes. In total, there are operations of type Q and C.
For each Q operation and C operation, output the corresponding result.
Input Format
The first line contains two integers , representing the number of servers and the number of query operations.
The next lines each describe one operation.
Output Format
Output lines:
- For a
Qoperation, outputyesornoto indicate whether it has data block . - For a
Coperation, output one integer representing the number of servers.
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
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
Hint
Constraints
This problem uses bundled testdata.
- Subtask 1 (5 pts): .
- Subtask 2 (5 pts): Server shares data with servers .
- Subtask 3 (10 pts): If , then server shares data with server .
- Subtask 4 (20 pts): If and or , then server shares data with server .
- Subtask 5 (25 pts): Each server shares data with at most servers.
- Subtask 6 (35 pts): No special restrictions.
For of the testdata, .
Notes
Translated from BalticOI 2021 Day1 B Inside information。
Translated by ChatGPT 5
京公网安备 11011102002149号