#P7307. [COCI 2018/2019 #1] Teoretičar
[COCI 2018/2019 #1] Teoretičar
Description
To avoid feeling bored, Alan asked Goran to come up with an interesting problem. Since he was busy preparing for exams, Goran only remembered a huge bipartite graph. He gave the bipartite graph to Alan and asked him to color all edges using as few colors as possible, such that edges of the same color do not share a common endpoint.
After seeing Alan’s complicated method, Goran decided to be merciful and gave a simplified version: let be the answer to the problem above, and let be the smallest positive integer power of that is not less than . You only need to output one coloring scheme that uses no more than colors.
Please help Alan solve this problem.
Note: A bipartite graph is a graph that can be split into two sets such that every edge connects a vertex from one set to a vertex from the other set.
Input Format
The first line contains positive integers , representing the number of vertices in the first set of the bipartite graph, the number of vertices in the second set, and the number of edges.
In the next lines, each line contains two positive integers , meaning there is an edge between the -th vertex in the first set and the -th vertex in the second set. The testdata guarantees that there are no multiple edges.
Output Format
The first line outputs a positive integer , the number of colors used.
In the next lines, output a positive integer () on each line, representing the color used for the -th edge.
3 3 5
1 1
1 2
2 2
2 3
3 3
2
1
2
1
2
1
2 4 4
1 1
1 2
1 3
2 4
4
1
2
3
4
Hint
Sample 2 Explanation
The minimum number of colors needed is . However, using colors is also feasible, because is the smallest positive integer power of that is not less than .
Constraints
For of the testdata, .
For another of the testdata, .
For of the testdata, , , , .
Notes
Only graded test points are used for evaluation here, so the full score is adjusted from to .
This problem is translated from COCI2018-2019 CONTEST #1 T5 Teoretičar.
Translated by ChatGPT 5
京公网安备 11011102002149号