One Walk
Time limit1sMemory limit1024 MB
Orient each edge of an undirected graph so that exactly one walk goes from S to E, or print -1 if that is impossible.
Problem
Given an undirected simple graph . Assign a direction to every edge of so that there is exactly one walk from a vertex to another vertex . A walk is a path that may visit the same vertices and edges several times.
Input
The first line contains the number of vertices , the number of edges , the start vertex , and the end vertex , separated by spaces. (; ; ; )
The next lines each contain two vertex numbers and connected by an edge, separated by a space. ()
Output
If no choice of edge directions makes the walk from to unique, print -1. Otherwise, print the direction of each edge in input order on one line. Print 0 if the edge is oriented as , and 1 if it is oriented the other way. If several outputs satisfy the condition, print any of them.