Logo
(追記) (追記ここまで)

24722번 - Usmjeravanje 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB111100.000%

문제

Peter Pan was given career guidance to help determine his future profession. As he does not want to grow up, he ran away and sought shelter in Neverland. There are two rivers in Neverland, flowing from west to east. On the shore of the first river, there are $a$ cities, labeled with positive integers from 1ドル$ to $a$ in the same direction that the river flows. Similarly, on the shore of the second river there are $b$ cities labeled in the same direction from 1ドル$ to $b$. Traveling downstream, it’s possible to reach city $j$ from city $i$ if both of these cities are on the same river and if $i < j$.

Citizens of Neverland plan to establish $m$ one-way flight routes. It is given that the $i$-th route should connect city $x_i$ from the first river and city $y_i$ from the second river, but it has not yet been decided in which direction. The citizens of Neverland would like their cities to be as connected as possible. At that moment Peter Pan realized that he would like to direct flight routes for a living.

A pair of cities is called connected if it is possible to reach the second city starting from the first, and vice versa. While traveling, it is allowed to use both flight routes and rivers. Peter Pan wants to determine the route directions in order to minimize the largest set of cities in which no pair of cities is connected. Help Peter Pan and determine how to direct the routes and what would the size of the mentioned set be in that case.

입력

The first line contains positive integers $a,ドル $b$ and $m$ (1ドル ≤ a, b, m ≤ 200,000円$), the number of cities on the first river, the number of cities on the second river and the number of flight routes, respectively.

The $i$-th of the next $m$ lines contains two positive integers $x_i$ and $y_i$ (1ドル ≤ x_i ≤ a,ドル 1ドル ≤ y_i ≤ b$) which denote a flight route connecting city $x_i$ from the first river and city $y_i$ from the second river. No pair of cities is listed more than once.

출력

In the first line print the least possible size of the maximum set of cities in which no pair of cities is connected.

In the second line print a sequence of characters 0 or 1 separated by spaces which denote the directions of the flight routes. The character 0 means that the flight takes off from the first river and lands on the second river, and conversely for 1. If there is more than one solution, output any.

제한

서브태스크

번호배점제한
120

1ドル ≤ a, b, m ≤ 15$

230

1ドル ≤ a, b ≤ 1000$

360

No additional constraints.

예제 입력 1

5 3
4
1 2
2 3
3 1
5 3

예제 출력 1

1
1 1 0 0

예제 입력 2

6 6
4
1 2
3 2
4 3
5 6

예제 출력 2

9
1 0 1 1

예제 입력 3

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

예제 출력 3

5
1 0 1 1 0 1 0

힌트

Clarification of the first example:

If the flights are directed as shown in the output, it is possible to reach any city starting from any other city. Therefore, the largest set containing no pair of connected cities is a singleton. For example, it’s possible to reach city 1 from the first river by starting from city 5 from the first river:

5 (I) → 3 (II) → 2 (I) → 3 (I) → 1 (II) → 2 (II) → 1 (I).

출처

Contest > Croatian Open Competition in Informatics > COCI 2021/2022 > Contest #5 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /