RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00497

Teoretičar

Unrated 레이팅 미적용
난이도
6s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

6 \(s / 256\) \(MB / 130\) points

Little Alan was bored so he asked Goran to give him an interesting problem. Since he's busy with

preparing for exams, Goran could only recall one huge bipartite graph from his old days as a

programming competitor. He gave the graph to Alan and said: You have \(to\) colour the edges \(of\) this

bipartite graph using \(as\) few colours \(as\) possible \(in\) such \(a\) way that there are \(no\) two edges \(of\) the

same colour sharing a node.

Alan excitedly ran to his room, took out his movable re\(ad/wr\)ite device for its tape and start to work on

the problem. However, he soon realized that he's missing something so he got back to Goran and

said: Give \(me\) an infinite tape and I will solve your problem! Goran gave him a significant look: Infinite

tape? If you continue to theorize about everything, there won't be a single thing named after you.

After seeing Alan starting to tear up, Goran decided to show mercy: I will make it a bit easier for you.

Let \(C\) \(be\) the smallest number of colours needed to paint the graph in the described way. I will let you

use at most X colours, where X is the lowest power of 2 not less than C.

Help Alan solve the problem.

Note : A bipartite graph is a graph whose nodes can be divided in two sets (or sides) in such a way

that each edge of graph connects one node from the first set with one node from the second set.

제약

In test cases worth 20% of total points, it will hold that L, R ≤ 100.
In test cases worth additional 20% of total points, it will hold that L, R ≤ 5 000.

6 \(s / 256\) \(MB / 130\) points

입력 형식

The first line contains three positive integers: \(L\) , \(R\) and \(M\) (1 ≤ L, \(R \le 100\,000\), \(1 \le M \le 500\,000\)),

representing the number of nodes in one side of the bipartite graph, number of nodes in the other

side of the bipartite graph and the number of edges, in that order.
\(M\) lines follow, each containing two positive integers \(a\) {i} (1 ≤ \(a\) \(L\) ) and \(b\) {i} (1 ≤ \(b\) \(R\) ) which represent

an edge between \(a\) {i}{ }-th node from the first side and \(b\) {i}{ }-th node from the second side of the bipartite

graph. All pairs ( \(a\) {i}{ }, \(b\) {i}{ }) will be unique.

출력 형식

In the first line output a single positive integer \(K\) , the number of colours used.
In the next \(M\) lines output a single positive integer \(c\) {i}{ } (1 ≤ \(c\) {i}{ } ≤ \(K\) ), label of the colour of the \(i-th\) edge.

예제 1
입력
3 3 5
1 1
1 2
2 2
2 3
3 3

2 4 4
1 1
1 2
1 3
2 4
출력
output
2
1
2
1
2
1

4
1
2
3
4
설명

Clarification of the second sample test:
Minimal number of colours is equal to 3. However, using 4 colours is also acceptable because that’s the lowest

power of 2 which is not less than 3.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2018/2019 Contest 1

평가 및 의견

Teoretičar

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Teoretičar

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8