EVENCYCLE
Problem
Given an undirected graph consisting of vertices and
edges, find a cycle with an even number of edges, if it exists.
Input:
The first line of the input will contain a positive integer , the number of queries to answer.
Each of the next
queries will begin with a line containing two natural numbers
and
separated by a space: the number of vertices and the number of edges of the graph.
Following this, there will be
lines, each containing two natural numbers
and
separated by a space, representing an edge between vertices
and
.
Assume vertices are numbered from
to
, and no two edges connecting the same pair of vertices in the graph will be given.
Output:
The output should contain exactly lines, each one corresponding to an answer to a query in the order they are given.
Each answer line will contain either:
- The word "cycle", followed by an even positive integer
(the number of edges in the cycle), followed by
integers
,
,
,
. This answer indicates that the requested cycle has been found. To be valid, such an answer must satisfy
(as a single edge is not considered a cycle), the numbers
,
,
,
must be pairwise distinct vertices of the cycle, there must be an edge (
,\;
) for each
, and there must also be an edge
to complete the cycle. If there are multiple cycles with an even number of edges, you may print any of them.
- The word "none", if there is no cycle with an even number of edges. All words and numbers on each line of the output should be separated in pairs by a single space.
Constraints
and
. Of course, it will be true that
.
and
for every edge given, and also
.
- The sum of all
queries will not exceed
, and the sum of all
queries will not exceed
.
- Time Limit:
sec.
Memory Limit:
MB.
For test cases with a total value of
, it will be
.
- For test cases with a total value of
, it will be
and
.
- For test cases with a total value of
, the vertices of the graph can be colored using two colors in such a way that there are no edges between vertices of the same color.
- For test cases with a total value of
, each vertex of the graph will be connected to at most two other vertices.
- For test cases with a total value of
, each vertex of the graph will be connected to at most three other vertices (and there will be vertices that are connected exactly to three other vertices.).
- For the rest of the test cases with a total value of
, none of the above special constraints will apply..
Example of Input - Output Files:
Note: For your convenience, in the example that follows, the three input queries are separated from each other.
evencycle.in | evencycle.out | |
4 5 1 2 1 3 2 3 3 4 4 1 |
cycle 4 3 2 1 4 | |
5 6 1 2 1 3 1 4 1 5 2 3 4 5 |
none | |
7 6 1 7 3 4 4 5 5 6 6 3 5 2 |
cycle 4 6 3 4 5 | |
Comments