#abc239f. F - Construct Highway
F - Construct Highway
Score : points
问题陈述
在Atcoder共和国,有编号为 到 的 个城镇以及编号为 到 的 条高速公路。
高速公路 双向连接城镇 和城镇 。
高桥国王计划新建 条新高速公路,以满足以下两个条件:
- 使用一些数量的高速公路可以从任意一对城镇之间通行
- 对于每 ,恰好有 条高速公路直接与城镇 相连
确定是否存在这样的建设方式。如果存在,输出一种方案。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
The Republic of Atcoder has towns numbered through , and highways numbered through .
Highway connects Town and Town bidirectionally.
King Takahashi is going to construct new highways so that the following two conditions are satisfied:
- One can travel between every pair of towns using some number of highways
- For each , exactly highways are directly connected to Town
Determine if there is such a way of construction. If it exists, print one.
Constraints
- If , then .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there isn't a way of construction that satisfies the conditions, print -1
.
If there is, print lines. The -th line should contain the indices of the two towns connected by the -th highway to be constructed.
Sample Input 1
6 2
1 2 1 2 2 2
2 3
1 4
Sample Output 1
6 2
5 6
4 5
As in the Sample Output, the conditions can be satisfied by constructing highways connecting Towns and , Towns and , and Towns and , respectively.
Another example to satisfy the conditions is to construct highways connecting Towns and , Towns and , and Towns and , respectively.
Sample Input 2
5 1
1 1 1 1 4
2 3
Sample Output 2
-1
Sample Input 3
4 0
3 3 3 3
Sample Output 3
-1
update @ 2024/3/10 10:19:26