#K96357. Box Operations Simulation
Box Operations Simulation
Box Operations Simulation
You are given a series of operations to simulate a collection of boxes and the items contained in them. There are four types of operations:
- CREATE X: Create a box with identifier \(X\) and initialize it to be empty.
- ADD X Y: Add an item with identifier \(Y\) to box \(X\).
- MOVE X Y: Move all items from box \(X\) to box \(Y\). After the move, box \(X\) becomes empty.
- QUERY X: Output the number of items currently in box \(X\).
Operations are given in the order they must be executed. For every QUERY
operation, you need to print the result on a separate line.
Note: All numbers in the operations are positive integers.
inputFormat
The first line contains a single integer \(N\) representing the number of operations. The following \(N\) lines each contain one operation in one of the four formats described above.
outputFormat
For each QUERY
operation, output a line with a single integer which is the number of items in the specified box.
7
CREATE 1
CREATE 2
ADD 1 101
ADD 1 102
MOVE 1 2
QUERY 1
QUERY 2
0
2
</p>