#P7370. [COCI 2018/2019 #4] Wand

[COCI 2018/2019 #4] Wand

Description

NN wizards, labeled 1,2,,N1,2,\cdots,N, will take part in MM duels.

There is a wand. If the wand currently belongs to wizard AA, and wizard AA is defeated by wizard BB, then the wand will belong to wizard BB. Initially, the wand belongs to wizard 11.

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 N,MN, M.

Each of the next MM lines contains positive integers Xi,YiX_i, Y_i, meaning wizard XiX_i will defeat wizard YiY_i.

Output Format

Output NN characters. If the wand may finally belong to wizard kk, output 1 at the kk-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 11 and 33 duel first, and then it is wizards 22 and 33, the wand will finally belong to wizard 22.

If wizards 22 and 33 duel first, and then it is wizards 11 and 33, the wand will finally belong to wizard 33.

Constraints

For 20%20\% of the testdata, 1N,M101 \le N, M \le 10.

For 100%100\% of the testdata, 1N,M1051 \le N, M \le 10^5, 1Xi,YiN1 \le X_i, Y_i \le N, and XiYiX_i \neq Y_i.

Notes

The scoring of this problem follows the original COCI settings, with a full score of 7070.

Translated from COCI2018-2019 CONTEST #4 T2 Wand.

Translated by ChatGPT 5