题目收集
题目列表题单
返回列表

Odd Cycle or 3-Coloring

CodeforcesP0061· 1000ms· 256 MB· ZJU Summer 2026 Contest 6原题链接
图论构造

创建于 2026/07/18 · 更新于 2026/07/18

题目描述

You are given a connected, simple, undirected graph with nnn vertices and mmm edges.

We call a simple cycle safely removable if deleting all of its edges keeps the graph connected.

You should complete exactly one of the two tasks below (you choose which one), and you do not need to do both. It can be proved that at least one of the two tasks is always achievable.

1. 3-color the graph: give each vertex a color in {1,2,3}\{1,2,3\}{1,2,3} so that the two endpoints of every edge get different colors.

2. Find a safely removable odd cycle: output a simple cycle of odd length that is safely removable.

输入格式

The first line contains nnn and mmm. Each of the next mmm lines contains two integers xxx and yyy (1≤x,y≤n1 \le x, y \le n1≤x,y≤n, x≠yx \ne yx=y), meaning there is an edge between vertices xxx and yyy. The graph is connected and has no self-loops or repeated edges.

1≤n≤1051 \le n \le 10^{5}1≤n≤105, 1≤m≤2⋅1051 \le m \le 2 \cdot 10^{5}1≤m≤2⋅105.

输出格式

For task 1, print 1\mathbf{1}1, then a line of nnn integers c1,…,cnc_1, \ldots, c_nc1​,…,cn​ (1≤ci≤31 \le c_i \le 31≤ci​≤3).

For task 2, print 2\mathbf{2}2, then a line with the odd cycle length LLL followed by the LLL cycle vertices v1,…,vLv_1, \ldots, v_Lv1​,…,vL​ in order.

Any valid answer is accepted by a special judge.

样例输入 #1

3 3
1 2
3 2
1 3

样例输出 #1

1
1 2 3

样例输入 #2

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

样例输出 #2

2
3 3 4 2

样例输入 #3

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

样例输出 #3

1
1 1 1 2 1 2