COCI '21 Contest 5 #5 Usmjeravanje
View as PDF
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  cities, labeled with positive integers from 
 to 
 in the same direction
that the river flows. Similarly, on the shore of the second river there are 
 cities
labeled in the same direction from 
 to 
. Traveling downstream, it's possible to
reach city 
 from city 
 if both of these cities are on the same river and if 
.
Citizens of Neverland plan to establish  one-way flight routes. It is given that the 
 route should
connect city 
 from the first river and city 
 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.
Input Specification
The first line contains positive integers , 
, and 
 
, the number of cities on the
first river, the number of cities on the second river and the number of flight routes, respectively.
The  of the next 
 lines contains two positive integers 
 and 
 
 which denote
a flight route connecting city 
 from the first river and city 
 from the second river. No pair of cities is
listed more than once.
Output Specification
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.
Constraints
| Subtask | Points | Constraints | 
|---|---|---|
| No additional constraints. | 
Sample Input 1
5 3
4
1 2
2 3
3 1
5 3
Sample Output 1
1
1 1 0 0
Explanation for Sample Output 1
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  from the first river by starting from city 
 from the first river:
Sample Input 2
6 6
4
1 2
3 2
4 3
5 6
Sample Output 2
9
1 0 1 1
Sample Input 3
8 7
7
1 3
2 1
3 4
5 6
6 5
6 7
8 7
Sample Output 3
5
1 0 1 1 0 1 0
Comments