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

Connect the Graph

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 719    Accepted Submission(s): 261
Special Judge


Problem Description
Once there was a special graph. This graph had $n$ vertices and some edges. Each edge was either white or black. There was no edge connecting one vertex and the vertex itself. There was no two edges connecting the same pair of vertices. It is special because the each vertex is connected to at most two black edges and at most two white edges.

One day, the demon broke this graph by copying all the vertices and in one copy of the graph, the demon only keeps all the black edges, and in the other copy of the graph, the demon keeps all the white edges. Now people only knows there are $w_0$ vertices which are connected with no white edges, $w_1$ vertices which are connected with $1$ white edges, $w_2$ vertices which are connected with $2$ white edges, $b_0$ vertices which are connected with no black edges, $b_1$ vertices which are connected with $1$ black edges and $b_2$ vertices which are connected with $2$ black edges.

The precious graph should be fixed to guide people, so some people started to fix it. If multiple initial states satisfy the restriction described above, print any of them.
 

Input
The first line of the input is a single integer $T \ (T \le 700)$, indicating the number of testcases.

Each of the following $T$ lines contains $w_0,w_1,w_2,b_0,b_1,b_2$. It is guaranteed that $1 \le w_0,w_1,w_2,b_0,b_1,b_2 \le 2000$ and $b_0+b_1+b_2=w_0+w_1+w_2$.

It is also guaranteed that the sum of all the numbers in the input file is less than $300000$.
 

Output
For each testcase, if there is no available solution, print $-1$. Otherwise, print $m$ in the first line, indicating the total number of edges. Each of the next $m$ lines contains three integers $x,y,t$, which means there is an edge colored $t$ connecting vertices $x$ and $y$. $t=0$ means this edge white, and $t=1$ means this edge is black. Please be aware that this graph has no self-loop and no multiple edges. Please make sure that $1 \le x, y \le b_0 + b_1 + b_2$.
 

Sample Input
2 1 1 1 1 1 1 1 2 2 1 2 2
 

Sample Output
-1 6 1 5 0 4 5 0 2 4 0 1 4 1 1 3 1 2 3 1
 

Author
XJZX
 

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 19:44:49, Gzip enabled