P29601 [洛谷] [COCI2018-2019#4] Wand
普及+
题目描述

Problem Description

$N$ wizards, numbered $1, 2, \cdots, N$, will participate in $M$ duels.

There is a magic wand. If the wand currently belongs to wizard A, and wizard A is defeated by wizard B, the wand will then belong to wizard B. The wand initially belongs to wizard $1$.

Kile wants to know, under the condition of only adjusting the order of duels, who the wand might eventually belong to.

Input Format

The first line contains two positive integers $N$ and $M$.

The next $M$ lines contain two positive integers $X_i$ and $Y_i$, indicating that wizard $X_i$ will defeat wizard $Y_i$.

Output Format

Output $N$ characters, where if the wand might eventually belong to wizard $k$, output $1$ at the $k$-th character, otherwise output $0$.

Sample Input and Output

Sample Input #1

3 2
2 3
3 1

Sample Output #1

011

Sample Input #2

2 2
2 1
1 2

Sample Output #2

11

Sample Input #3

5 5
3 1
2 1
4 3
4 5
2 5

Sample Output #3

01110

Notes

Sample 1 Explanation

If wizards $1, 3$ duel first, followed by wizards $2, 3$, the wand will eventually belong to wizard $2$.

If wizards $2, 3$ duel first, followed by wizards $1, 3$, the wand will eventually belong to wizard $3$.

Data Size and Constraints

For $20\%$ of the data, $1 \le N, M \le 10$.

For $100\%$ of the data, $1 \le N, M \le 10^5$, $1 \le X_i, Y_i \le N$, $X_i \neq Y_i$.

Note

This problem's score is set according to the original COCI contest, with a maximum score of $70$.

The problem is translated from COCI2018-2019 CONTEST #4 T2 Wand.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 2 3 3 1
样例输出
011