QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 512 MB 總分: 100

#3315. 欧拉飞行巡回

统计

你拥有一张某地区的航线图。该地区的所有机场以及它们之间的所有直达航线都在地图上。这里,直达航线是指一种双向的飞行路线。

以伟大的数学家莱昂哈德·欧拉(Leonhard Euler)的名字命名,欧拉回路(Eulerian tour)是指一种行程,它通过该地区所有可用的直达航线,且每条航线恰好经过一次。准确地说,它是一个机场列表,满足以下所有条件:

  • 列表的起点和终点是同一个机场。
  • 列表中相邻的机场对之间存在直达航线。
  • 该地区的所有机场在列表中至少出现一次。注意,允许某些机场出现多次。
  • 对于所有存在直达航线的机场对,在列表中必须恰好有一次相邻出现(无论顺序如何)。

仅使用地图上列出的直达航线并不总能找到欧拉回路。然而,增加更多的航线可能会使欧拉回路成为可能。你的任务是找到一组能够实现欧拉回路的额外航线。

输入格式

输入包含单个测试用例。

$n$ $m$ $a_1$ $b_1$ $\vdots$ $a_m$ $b_m$

$n$ ($3 \le n \le 100$) 是机场的数量。机场编号从 $1$ 到 $n$。$m$ ($0 \le m \le \frac{n(n-1)}{2}$) 是拥有直达航线的机场对数量。在接下来的 $m$ 行中,第 $i$ 行的整数 $a_i$ 和 $b_i$ ($1 \le i \le m$) 表示存在直达航线的机场编号。你可以假设 $1 \le a_i < b_i \le n$,并且对于任何 $i \neq j$,要么 $a_i \neq a_j$,要么 $b_i \neq b_j$ 成立。

输出格式

输出一组能够实现欧拉回路的额外直达航线。如果存在多组不同的方案,输出其中任意一组即可。输出应遵循以下格式:

$k$ $c_1$ $d_1$ $\vdots$ $c_k$ $d_k$

$k$ 是需要添加的直达航线数量,可能为零。接下来的 $k$ 行,每行应包含一对由空格分隔的整数。第 $i$ 行的整数 $c_i$ 和 $d_i$ ($c_i < d_i$) 是指定要在其间添加直达航线的机场编号。这些对 $(c_i, d_i)$(对于 $1 \le i \le k$)必须各不相同,且不能出现在输入中。

如果添加新的直达航线永远无法实现欧拉回路,则输出一行 -1。

样例

样例输入 1

4 2
1 2
3 4

样例输出 1

2
1 4
2 3

样例输入 2

6 9
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6

样例输出 2

-1

样例输入 3

6 7
1 2
1 3
1 4
2 3
4 5
4 6
5 6

样例输出 3

3
1 5
2 4
2 5

样例输入 4

4 3
2 3
2 4
3 4

样例输出 4

-1

样例输入 5

5 5
1 3
1 4
2 4
2 5
3 5

样例输出 5

0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.