#P5966. [POI 2016] Hydrorozgrywka

[POI 2016] Hydrorozgrywka

Problem Description

You are given a connected undirected graph with nn vertices and mm edges. It is guaranteed that each edge belongs to one and only one cycle.

Two players play a game on this graph. At the beginning, they place a token on some vertex, and then they move the token alternately. An edge that has already been used cannot be used again. The player who cannot make a move loses.

Please find all starting positions (the vertex where the token is placed at the start) among all winning strategies for the first player.

Input Format

The first line contains two positive integers n,mn, m, representing the number of vertices and the number of edges.

The next mm lines each contain two positive integers a,ba, b, indicating that there is an undirected edge between vertex aa and vertex bb.

Output Format

Output nn lines. For the ii-th line, if placing the token at vertex ii makes the first player win, output 1; otherwise output 2.

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

Hint

For 100%100\% of the testdata, 3n,m5×1053 \le n, m \le 5 \times 10^5, 1a,bn1 \le a, b \le n, and aba \ne b.

Translated by ChatGPT 5