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 arepairs 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.
INPUT FORMAT (file gathering.in):
Linecontains two space-separated integers and .Lines each contain two integers and with and indicating that cows and are friends.
Lineseach 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 .
OUTPUT FORMAT (file gathering.out):
The output should consist oflines, with one integer on each line such that if cow could be the last to leave, and otherwise.
5 1 1 2 2 3 3 4 4 5 2 4
0 0 1 1 1
Problem credits: Dhruv Rohatgi