

Time Limit: 4 sec / Memory Limit: 1024 MB
配点 : 点
問題文
の部分集合が 個与えられます。 番目の集合を とします。
各集合 から相異なる 要素 を選び、 を頂点集合、 を辺集合とするような、 頂点 辺グラフ を考えます。 うまく を定めることにより、 を木にすることができるかどうか判定してください。 さらに可能な場合は、 が実際に木となるような を一つ求めてください。
制約
- は の部分集合である。
- の和は 以下である。
入力
入力は以下の形式で標準入力から与えられる。
ただし、 は の要素数を指し、 は の 個の元である。 また、, , () である。
出力
を木とすることができない場合は -1
を出力せよ。そうでない場合は以下の形式に従って条件を満たす を出力せよ。
入力例 1Copy
5 2 1 2 3 1 2 3 3 3 4 5 2 4 5
出力例 1Copy
1 2 1 3 3 4 4 5
入力例 2Copy
6 3 1 2 3 3 2 3 4 3 1 3 4 3 1 2 4 3 4 5 6
出力例 2Copy
-1
入力例 3Copy
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
出力例 3Copy
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10
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:
Sample Input 1Copy
5 2 1 2 3 1 2 3 3 3 4 5 2 4 5
Sample Output 1Copy
1 2 1 3 3 4 4 5
Sample Input 2Copy
6 3 1 2 3 3 2 3 4 3 1 3 4 3 1 2 4 3 4 5 6
Sample Output 2Copy
-1
Sample Input 3Copy
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
Sample Output 3Copy
1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10