MZL's endless loop

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.
SampleInput
2
3 3
1 2
2 3
3 1
7 6
1 2
1 3
1 4
1 5
1 6
1 7
SampleOutput
1
1
1
0
1
0
1
0
1
Submit
题目统计信息详细
总AC数3
通过人数3
尝试人数5
总提交量15
AC率20.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: