atcoder#AGC029F. [AGC029F] Construction of a tree
[AGC029F] Construction of a tree
Score : points
Problem Statement
You are given subsets of . Let the -th set be .
Let us choose two distinct elements and from each set , and consider a graph with vertices and edges, whose vertex set is and whose edge set is . Determine if can be a tree by properly deciding and . If it can, additionally find one instance of such that is actually a tree.
Constraints
- is a subset of .
- The sum of is at most .
Input
Input is given from Standard Input in the following format:
Here, stands for the number of elements in , and are the elements in . Here, , , and () hold.
Output
If cannot be a tree, print -1
; otherwise, print the choices of that satisfy the condition, in the following format:
5
2 1 2
3 1 2 3
3 3 4 5
2 4 5
1 2
1 3
3 4
4 5
6
3 1 2 3
3 2 3 4
3 1 3 4
3 1 2 4
3 4 5 6
-1
10
5 1 2 3 4 5
5 2 3 4 5 6
5 3 4 5 6 7
5 4 5 6 7 8
5 5 6 7 8 9
5 6 7 8 9 10
5 7 8 9 10 1
5 8 9 10 1 2
5 9 10 1 2 3
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10