TimeLimit: 3000/1500 MS (Java/Others) MemoryLimit: 131072/131072 K (Java/Others)
64-bit integer IO format:%I64d
Special Judge
未提交 | 登录后收藏
Problem 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.
T≤100, 1≤n≤105, 1≤m≤3∗105, ∑n≤2∗105, ∑m≤7∗105.
Output
For each test case, if there is no solution, print a single line with $-1$, otherwise output $m$ lines,.
In i-th line contains a integer 1 or 0, 1 for direct the i-th edge to ui→vi, 0 for ui←vi.