#P8076. [COCI 2009/2010 #7] RESTORAN

[COCI 2009/2010 #7] RESTORAN

Problem Description

You are given an undirected graph with NN nodes and EE edges.

Now you may color these EE edges red or blue. Find a coloring such that every node whose degree is at least 22 is incident to edges of both colors. If there is no solution, output 00.

Input Format

The first line contains two integers N,EN, E.

The next EE lines each contain two integers Ai,BiA_i, B_i, meaning the ii-th edge connects nodes AiA_i and BiB_i. The testdata guarantees that there are no multiple edges.

Output Format

If there is no solution, output 00.

Otherwise, output EE lines. Each line gives the color of an edge (in the same order as the input). Use 11 for red and 22 for blue.

If multiple solutions exist, output any one of them.

5 6
1 2
2 3
3 1
3 4
1 4
4 5
1
2
1
2
2
1
7 7
1 2
2 3
3 1
4 5
5 6
6 7
7 4
0
77777 4
1 2
1 3
1 4
1 5
1
2
2
2

Hint

Constraints

This problem uses bundled testdata.

  • Subtask 1 (78 pts): N1000N \le 1000, E5000E \le 5000.
  • Subtask 2 (52 pts): no additional constraints.

For 100%100\% of the testdata, 1N,E1051 \le N, E \le 10^5.

Hints and Notes

You are welcome to hack the self-written Special Judge by private message or by making a post.

Translated from COCI 2009-2010 CONTEST #7 Task 6 RESTORAN.

The score settings follow the original COCI problem, with a full score of 130130.

Translated by ChatGPT 5