QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#10911. 三正则图问题

Statistics

一只可怜的小企鹅被虎鲸抛到了十万八千里之外。随后,这只可怜的小企鹅发现自己身处一座神秘的岛屿上。地面上有许多图。小企鹅发现所有的顶点度数均为 3。“道生一,一生二,二生三,三生万物”,小企鹅回想起了这句玄妙的话。突然,一支羽毛笔出现在眼前。一个声音说道:“每次你将羽毛笔蘸入海中,你都可以一笔画出三条边。也就是说,你可以从一个顶点出发,经过三条不同的边到达另一个顶点。”这是一只头顶有三根金羽毛的鹦鹉,“如果一个图的所有边都能以这种方式被恰好画一次,那么我们就称它为‘三投图’(Three-throwable graph)。你应该找出所有的三投图,并向我展示如何投掷三次!一旦你完成了,我将赐予你‘万物之力’,并送你回去向那只虎鲸复仇!”

图太多了!所以这只可怜的小企鹅向你们三位求助。请帮助它,为了光明与正义。

简而言之,给定一个有 $n$ 个顶点和 $m$ 条边的图,其中 $n$ 为偶数,且所有顶点的度数均为 3。因此可以得出 $m = \frac{3n}{2}$,且 $m$ 是 3 的倍数。你应该尝试将该图拆分为 $\frac{m}{3}$ 条长度为 3 的链。确定该图是否为三投图(即是否存在这样的链拆分方案),如果存在,请输出拆分后的链。

输入格式

第一行包含两个整数 $n, m$ ($2 \le n \le 500$),表示顶点数和边数。 接下来 $m$ 行,每行包含两个整数 $u, v$ ($1 \le u, v \le n$),表示连接顶点 $u$ 和 $v$ 的一条边。 保证 $n$ 为偶数,$m = \frac{3n}{2}$,且所有顶点的度数均为 3。

输出格式

如果该图不是三投图,则输出一行 “IMPOSSIBLE”(不含引号)。 否则,输出 $\frac{m}{3}$ 行,每行包含四个整数 $a_i, b_i, c_i, d_i$,表示一条包含三条边 $a_i \leftrightarrow b_i, b_i \leftrightarrow c_i, c_i \leftrightarrow d_i$ 的链。给定边的多重集与所有链边的多重集必须相同。如果存在多种解,输出其中任意一种即可。

样例

样例输入 1

2 3
1 2
1 2
1 2

样例输出 1

2 1 2 1

样例输入 2

4 6
1 1
1 2
2 3
2 3
3 4
4 4

样例输出 2

1 1 2 3
2 3 4 4

样例输入 3

4 6
1 1
2 2
3 3
1 4
2 4
3 4

样例输出 3

IMPOSSIBLE

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.