문제
Cows have assembled from around the world for a massive gathering. There are cows, and 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 pairs of cows such that cow must leave before cow . Note that the cows and 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 contains two space-separated integers and .
Lines each contain two integers and with and indicating that cows and are friends.
Lines each contain two integers and with and indicating that cow must leave the gathering before cow .
It is guaranteed that . In test cases worth of the points, it is further guaranteed that .
출력
The output should consist of lines, with one integer on each line such that if cow could be the last to leave, and otherwise.
예제 입력 1
5 1
1 2
2 3
3 4
4 5
2 4
예제 출력 1
0
0
1
1
1
코드를 제출하려면 로그인이 필요합니다.
로그인