当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2202:Strange Graph

Special Judge 特殊评判
题目描述
Let us consider an undirected graph G = < V,E >. Let us denote by N(v) the set of vertices connected to vertex v (i.e. the set of neighbours of v). Recall that the number of vertices connected to v is called the degree of this vertex and is denoted by deg v.
We will call graph G strange if it is connected and for its every vertex v the following conditions are satisfied:
1. deg v >= 2 (i.e. there are at least two vertices connected to v)
2. If deg v = 2 then the two neighbours of v are not connected by an edge
3. If degv > 2 then there is u ∈ N(v), such that the following is true:
(a) deg u = 2
(b) Any two different vertices w1,w2 ∈ N(v) \ {u} are connected, i.e. (w1,w2) ∈ E.

You are given some strange graph G. Find hamiltonian cycle in it, i.e. find such cycle that it goes through every vertex of G exactly once.
输入解释
The first line of the input file contains two integer numbers N and M -- the number of vertices and edges in G respectively (3 <= N <= 10 000, M <= 100 000). 2M integer numbers follow -- each pair represents vertices connected by the corresponding edge (vertices are numbered from 1 to N). It is guaranteed that each edge occurs exactly once in the input file and that there are no loops (i.e. ends of each edge are distinct).
输出解释
If there is no hamiltonian cycle in G, print -1 on the first line of the output file. In the other case output N numbers -- the sequence of vertices of G as they appear in the hamiltonian cycle found (note that the last vertex must be connected to the first one). If there are several solutions, output any one.
输入样例
4 4
1 2 2 3 3 4 4 1
输出样例
1 2 3 4
来自北京大学POJ的附加信息
Case time limit(单组数据时间限制) 2000MS

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2202

最后修改于 2020-10-29T06:26:31+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000 65536