MZL's endless loop

Time Limit
2s
Memory Limit
131072KB
Judge Program
Special
Ratio(Solve/Submit)
0.00%(0/2)
Description:

As we all kown, MZL hates the endless loop deeply, and he commands you to solve this problem to end the loop.
You are given an undirected graph with n vertexs and m edges. Please direct all the edges so that for every vertex in the graph the inequation |out degree  in degree|1 is satisified.
The graph you are given maybe contains self loops or multiple edges.

Input:

The first line of the input is a single integer T, indicating the number of testcases.
For each test case, the first line contains two integers n and m.
And the next m lines, each line contains two integers ui and vi, which describe an edge of the graph.
T100, 1n105, 1m3105, n2105, m7105.

Output:

For each test case, if there is no solution, print a single line with 1, otherwise output m lines,.
In ith line contains a integer 1 or 0, 1 for direct the ith edge to uivi, 0 for uivi.

Sample Input:
2
3 3
1 2
2 3
3 1
7 6
1 2
1 3
1 4
1 5
1 6
1 7
Sample Output:
1
1
1
0
1
0
1
0
1
Source:

2015 Multi-University Training Contest 5


Submit