#abc260f. F - Find 4-cycle
F - Find 4-cycle
Score : points
问题描述
我们有一个简单的无向图 ,包含 个顶点和 条边。顶点编号从 到 ,边编号从 到 。第 条边连接顶点 和 。
这里,顶点集合 和 都是独立集。
长度为 的环称为 4-环。
如果 中包含一个 4-环,请任意选择其中一个,并按照任意顺序打印该环中的顶点。
如果 不包含 4-环,则打印 -1
。
什么是独立集?在图 中,独立集 是 中一些顶点的集合,其中任意两个顶点之间都没有边相连。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a simple undirected graph with vertices and edges. The vertices are numbered through , and the edges are numbered through . Edge connects Vertices and .
Here, vertex sets and are both independent sets.
A cycle of length is called a 4-cycle.
If contains a 4-cycle, choose any of them and print the vertices in the cycle. You may print the vertices in any order.
If does not contain a 4-cycle, print -1
.
What is an independent set? An independent set of a graph is a set of some of the vertices in such that no two vertices of have an edge between them.
Constraints
- If , then .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If contains a 4-cycle, choose any of them, and print the indices of the four distinct vertices in the cycle. (The order of the vertices does not matter.)
If does not contain a 4-cycle, print -1
.
Sample Input 1
2 3 5
1 3
1 4
1 5
2 4
2 5
Sample Output 1
1 2 4 5
There are edges between Vertices and , and , and , and and , so Vertices , , , and form a 4-cycle. Thus, , , , and should be printed.
The vertices may be printed in any order. Besides the Sample Output, 2 5 1 4
is also considered correct, for example.
Sample Input 2
3 2 4
1 4
1 5
2 5
3 5
Sample Output 2
-1
Some inputs may give without a 4-cycle.
Sample Input 3
4 5 9
3 5
1 8
3 7
1 9
4 6
2 7
4 8
1 7
2 9
Sample Output 3
1 7 2 9
update @ 2024/3/10 11:02:14