#P7370. [COCI 2018/2019 #4] Wand
[COCI 2018/2019 #4] Wand
Description
wizards, labeled , will take part in duels.
There is a wand. If the wand currently belongs to wizard , and wizard is defeated by wizard , then the wand will belong to wizard . Initially, the wand belongs to wizard .
Kile wants to know, if we are only allowed to change the order of the duels, who the wand may end up belonging to.
Input Format
The first line contains positive integers .
Each of the next lines contains positive integers , meaning wizard will defeat wizard .
Output Format
Output characters. If the wand may finally belong to wizard , output 1 at the -th character; otherwise output 0.
3 2
2 3
3 1
011
2 2
2 1
1 2
11
5 5
3 1
2 1
4 3
4 5
2 5
01110
Hint
Explanation for Sample 1
If wizards and duel first, and then it is wizards and , the wand will finally belong to wizard .
If wizards and duel first, and then it is wizards and , the wand will finally belong to wizard .
Constraints
For of the testdata, .
For of the testdata, , , and .
Notes
The scoring of this problem follows the original COCI settings, with a full score of .
Translated from COCI2018-2019 CONTEST #4 T2 Wand.
Translated by ChatGPT 5
京公网安备 11011102002149号