F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

MZL's endless loop

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 3598    Accepted Submission(s): 885
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|\leq 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 $u_i$ and $v_i$, which describe an edge of the graph.
$T\leq 100$, $1\leq n\leq 10^5$, $1\leq m\leq 3*10^5$, $\sum n\leq 2*10^5$, $\sum m\leq 7*10^5$.
 

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 $u_i\rightarrow v_i$, $0$ for $u_i\leftarrow v_i$.
 

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
 

Author
SXYZ
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 00:52:05, Gzip enabled