luogu#P5092. [USACO04OPEN] Cube Stacking
[USACO04OPEN] Cube Stacking
Problem Description
John and Bessie are playing a cube game. There are cubes numbered () placed on the ground at the start, each forming a single-cube pile.
After the game starts, John will give Bessie commands (). There are two types of commands:
- Move (
M): Move the pile containingXonto the top of the pile containingY. - Count (
C): Count how many cubes are below cubeXin the pile containingX.
Write a program to help Bessie complete the game.
Input Format
The first line contains . The next lines each contain one command, in the form M X Y or C X.
The input guarantees that there will be no command that moves a pile onto itself.
Output Format
For each count command, output one line with one integer, which is the result.
6
M 1 6
C 1
M 2 4
M 2 6
C 3
C 4
1
0
2
Hint
Some Constraints are shown in the Input Format.
.
Translated by ChatGPT 5