#398
Unrated
The Cow Gathering
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Cows have assembled from around the world for a massive gathering. There are NN cows, and N1N-1 pairs of cows who are friends with each other. Every cow knows every other cow through some chain of friendships.

They had great fun, but the time has come for them to leave, one by one. They want to leave in some order such that as long as there are still at least two cows left, every remaining cow has a remaining friend. Furthermore, due to issues with luggage storage, there are MM pairs of cows (ai,bi)(a_i, b_i) such that cow aia_i must leave before cow bib_i. Note that the cows aia_i and bib_i may or may not be friends.

Help the cows figure out, for each cow, whether she could be the last cow to leave. It may be that there is no way for the cows to leave satisfying the above constraints.

입력

Line 11 contains two space-separated integers NN and MM.

Lines 2iN2 \leq i \leq N each contain two integers xix_i and yiy_i with 1xi,yiN1 \leq x_i, y_i \leq N and xiyix_i \neq y_i indicating that cows xix_i and yiy_i are friends.

Lines N+1iN+MN+1 \leq i \leq N+M each contain two integers aia_i and bib_i with 1ai,biN1 \leq a_i, b_i \leq N and aibia_i \neq b_i indicating that cow aia_i must leave the gathering before cow bib_i.

It is guaranteed that 1N,M1051 \leq N, M \leq 10^5. In test cases worth 20%20\% of the points, it is further guaranteed that N,M3000N, M \leq 3000.

출력

The output should consist of NN lines, with one integer did_i on each line such that di=1d_i = 1 if cow ii could be the last to leave, and di=0d_i = 0 otherwise.

예제 입력 1

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

예제 출력 1

0
0
1
1
1
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.