连通的图的计算表达问题,要求使用C语言来实现

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 w0 vertices which are connected with no white edges, w1 vertices which are connected with 1 white edges, w2 vertices which are connected with 2 white edges, b0 vertices which are connected with no black edges, b1 vertices which are connected with 1 black edges and b2 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≤700), indicating the number of testcases.

Each of the following T lines contains w0,w1,w2,b0,b1,b2. It is guaranteed that 1≤w0,w1,w2,b0,b1,b2≤2000 and b0+b1+b2=w0+w1+w2.

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≤x,y≤b0+b1+b2.

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题

1
C语言的数据结构的连通图的问题,用C语言怎么编写代码去实现?
1
一个数据结构里的联通图方面的难题,用C语言请问大家怎么实现?
0
矩形叠加实现共同面积的联通问题,计算公共面积怎么利用C语言的方式
0
一个数据结构有关连通图生成算法的一个问题,用C语言怎么解决这个问题?
0
二维字符连通图的问题,运用C语言的知识的综合理解的实现
0
最小生成树判别多个节点之间的连通性的问题,如何利用C语言计算求解答
0
一个迷宫是否联通的有效性的判定算法怎么实现,采用C语言编程怎么实现
0
连通图的环的判断问题数据结构的设计,怎么利用C语言的编写形式?
0
一笔画连通的有效性的判断的问题,运用C语言的程序办法实现
0
连通图数据结构上面的一个路径的搜索的算法问题,采用C语言的程序的设计的办法
0
典型网络的连通的问题的算法问题,如何采用C语言的程序的设计的方式来实现的
0
连通图上的点的可达性的判断的算法问题,怎么利用C语言的程序的设计的方式来实现的?
0
连通图上的距离的搜索的问题,怎么利用C语言的程序的设计的方式实现的呢
0
连通图的稳定状态的计算用的数据结构,怎么采用C程序语言的编程算法的实现的过程
0
连通图的数据结构上的一个算法的视线,怎么能采用C语言的程序的设计的思想去实现?
0
联通图的连续性的判断问题,怎么使用C语言的程序设计的思想的代码的编写的过程来实现的?
0
C语言优化方案计算,使得n个传感器连通,并且所有传感器的Inference之和最小,具体代码实现的思路方式
0
C语言优化方案计算,使得n个传感器连通,并且所有传感器的Inference之和最小,怎么实现的呢
0
8个节点的连通图矩阵怎么用C语言的程序的编写设计的过程方式有效实现的思维是什么
0
轨道连通性的一个问题计算,怎么用C语言