bit gisect

아직 제출이 없습니다시간 제한20초메모리 제한256 MB

문제

Vasya the programmer is using Bit, a version control system for storing his code. The history of changes in Bit can be viewed as an oriented acyclic graph. The nodes of this graph are called revisions. When Vasya wants to make changes in the code, he can take an arbitrary revision AA and change the code, resulting in a new revision DD. In these case, we call the revision DD dependent of the revision AA. Each of these dependencies in Bit is expressed as an arc from the revision node AA to the revision node DD. Mergers are a special revision type in Bit: Vasya can join any two arbitrary revisions AA and BB and merge them into a new revision DD. In this case, the revision DD will depend on two revisions: AA and BB. The repository also contains a single "initial" revision: it is the only revision which does not depend on any other revision. All other revisions in Bit depend on one or more other revisions. Vasya has finished working on his project: there is strictly one revision which does not have any dependent revisions.

But one day, something went wrong, and the code became bug-ridden. Vasya is still trying to find them. Here is what Vasya's bugs do: if a bug appears in a revision AA, it affects all revisions accessible from AA in the Bit graph: the revision AA, all revisions dependent on AA, all revisions dependent on revisions dependent on AA, etc. To find the bug, Vasya can switch between revisions and check for the bug in the different revisions, thus narrowing down the suspect list. In the end, he will find the initial revision containing the bug.

Vasya is getting bug reports from the users, one after another, and he must find all these bugs, one by one. Help Vasya fix the code as quickly as possible.

The figure shows an example with 9 revisions. The revision 1 is the initial revision. The revisions 7, 8, and 9 are mergers, each depending on two other revisions. The revision 2, which sprouted a bug, and all dependent revisions suffering from that bug are highlighted in gray.