atcoder#AGC002B. [AGC002B] Box and Ball
[AGC002B] Box and Ball
Problem Statement
We have boxes, numbered through . At first, box contains one red ball, and each of the other boxes contains one white ball.
Snuke will perform the following operations, one by one. In the -th operation, he randomly picks one ball from box , then he puts it into box .
Find the number of boxes that may contain the red ball after all operations are performed.
Constraints
- Just before the -th operation is performed, box contains at least ball.
Input
The input is given from Standard Input in the following format:
Output
Print the number of boxes that may contain the red ball after all operations are performed.
3 2
1 2
2 3
2
Just after the first operation, box is empty, box contains one red ball and one white ball, and box contains one white ball.
Now, consider the second operation. If Snuke picks the red ball from box , the red ball will go into box . If he picks the white ball instead, the red ball will stay in box . Thus, the number of boxes that may contain the red ball after all operations, is .
3 3
1 2
2 3
2 3
1
All balls will go into box .
4 4
1 2
2 3
4 1
3 4
3