CF405E.Graph Cutting

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.

Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partition all edges of the graph into pairs in such a way that the edges in a single pair are adjacent and each edge must be contained in exactly one pair.

For example, the figure shows a way Chris can cut a graph. The first sample test contains the description of this graph.

You are given a chance to compete with Chris. Find a way to cut the given graph or determine that it is impossible!

小 Chris 正在参加一场图分割竞赛,他是一位高手。现在是时候全力考验他的能力了。

Chris 被给定一个包含 nn 个顶点(编号为 11 到 nn)和 mm 条边的简单无向连通图。问题要求将该图分割成若干条互不共享边的长度为 22 的路径。形式化地说,Chris 需要将图的所有边划分为若干对,使得每一对中的两条边相邻(即共享一个公共顶点),且每条边恰好属于其中一对。

例如,下图展示了一种 Chris 可行的图分割方式。第一个样例测试用例描述的就是该图。

你有机会与 Chris 同台竞技!请找出一种对该给定图的合法分割方式,或判定其不可能实现!

输入格式

The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105), the number of vertices and the number of edges in the graph. The next m lines contain the description of the graph's edges. The i-th line contains two space-separated integers a__i and b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i), the numbers of the vertices connected by the i-th edge. It is guaranteed that the given graph is simple (without self-loops and multi-edges) and connected.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

输入的第一行包含两个以空格分隔的整数 nn 和 mm(1≤n,m≤1051 \leq n, m \leq 10^5),分别表示图中的顶点数和边数。接下来的 mm 行描述图的边。第 ii 行包含两个以空格分隔的整数 aia_i 和 bib_i(1≤ai,bi≤n1 \leq a_i, b_i \leq n;ai≠bia_i \neq b_i),表示第 ii 条边所连接的两个顶点的编号。保证给定的图是简单图(不含自环和重边)且连通。

注意:由于输入和输出的数据量可能非常大,请勿在你的编程语言中使用低效的输入输出方式。例如,在 C++ 中不要使用输入输出流(cin、cout)。

输出格式

If it is possible to cut the given graph into edge-distinct paths of length 2, output lines. In the i-th line print three space-separated integers x__i, y__i and z__i, the description of the i-th path. The graph should contain this path, i.e., the graph should contain edges (x__i, y__i) and (y__i, z__i). Each edge should appear in exactly one path of length 2. If there are multiple solutions, output any of them.

If it is impossible to cut the given graph, print "No solution" (without quotes).

如果可以将给定图划分成若干条边互不相交的长度为 2 的路径,则输出 行。第 ii 行输出三个用空格分隔的整数 xix_i、yiy_i 和 ziz_i,表示第 ii 条路径。该图必须包含此路径,即图中必须包含边 (xi, yi)(x_i,\,y_i) 和 (yi, zi)(y_i,\,z_i)。每条边必须恰好出现在一条长度为 2 的路径中。若存在多种解法,输出任意一种即可。

若无法对给定图进行上述划分,则输出 "No solution"(不含引号)。

输入输出样例

  • 输入#1

    8 12
    1 2
    2 3
    3 4
    4 1
    1 3
    2 4
    3 5
    3 6
    5 6
    6 7
    6 8
    7 8

    输出#1

    1 2 4
    1 3 2
    1 4 3
    5 3 6
    5 6 8
    6 7 8
  • 输入#2

    3 3
    1 2
    2 3
    3 1

    输出#2

    No solution
  • 输入#3

    3 2
    1 2
    2 3

    输出#3

    1 2 3

输入解题思路,AI测评打分。不知道怎么写?

首页