VK Cup 2012 Round 3
A
Variable, or There and Back Again
Codeforces
1700
原题
←B →
翻译中…

Life is not easy for the perfectly common variable named Vasya. Wherever it goes, it is either assigned a value, or simply ignored, or is being used!

翻译中…

Vasya's life goes in states of a program. In each state, Vasya can either be used (for example, to calculate the value of another variable), or be assigned a value, or ignored. Between some states are directed (oriented) transitions.

翻译中…

A path is a sequence of states $*v*_{1}, *v*_{2}, ..., *v*_{*x*}$, where for any $1 ≤ *i* < *x*$ exists a transition from $*v*_{*i*}$ to $*v*_{*i* + 1}$.

翻译中…

Vasya's value in state $*v*$ is interesting to the world, if exists path $*p*_{1}, *p*_{2}, ..., *p*_{*k*}$ such, that $*p*_{*i*} = *v*$ for some $*i*$ $(1 ≤ *i* ≤ *k*)$, in state $*p*_{1}$ Vasya gets assigned a value, in state $*p*_{*k*}$ Vasya is used and there is no state $*p*_{*i*}$ (except for $*p*_{1}$) where Vasya gets assigned a value.

翻译中…

Help Vasya, find the states in which Vasya's value is interesting to the world.

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$) — the numbers of states and transitions, correspondingly.

翻译中…

The second line contains space-separated $*n*$ integers $*f*_{1}, *f*_{2}, ..., *f*_{*n*}$ ($0 ≤ *f*_{*i*} ≤ 2$), $*f*_{*i*}$ described actions performed upon Vasya in state $*i*$: $0$ represents ignoring, $1$ — assigning a value, $2$ — using.

翻译中…

Next $*m*$ lines contain space-separated pairs of integers $*a*_{*i*}, *b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$, $*a*_{*i*} ≠ *b*_{*i*}$), each pair represents the transition from the state number $*a*_{*i*}$ to the state number $*b*_{*i*}$. Between two states can be any number of transitions.

翻译中…

Output

翻译中…

Print $*n*$ integers $*r*_{1}, *r*_{2}, ..., *r*_{*n*}$, separated by spaces or new lines. Number $*r*_{*i*}$ should equal $1$, if Vasya's value in state $*i*$ is interesting to the world and otherwise, it should equal $0$. The states are numbered from $1$ to $*n*$ in the order, in which they are described in the input.

翻译中…

Note

翻译中…

In the first sample the program states can be used to make the only path in which the value of Vasya interests the world, 1 image 2 image 3 image 4; it includes all the states, so in all of them Vasya's value is interesting to the world.

翻译中…

The second sample the only path in which Vasya's value is interesting to the world is , — 1 image 3; state 2 is not included there.

翻译中…

In the third sample we cannot make from the states any path in which the value of Vasya would be interesting to the world, so the value of Vasya is never interesting to the world.

翻译中…

样例

Input #1
4 3
1 0 0 2
1 2
2 3
3 4
Output #1
1
1
1
1
InputCopy OutputCopy
Input #2
3 1
1 0 2
1 3
Output #2
1
0
1
InputCopy OutputCopy
Input #3
3 1
2 0 1
1 3
Output #3
0
0
0
InputCopy OutputCopy
题目信息
题号
164A
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。