#P8328. [COCI 2021/2022 #5] Usmjeravanje
[COCI 2021/2022 #5] Usmjeravanje
Problem Description
Neverland has two rivers. Along each river there are several cities, with the numbers of cities being and , respectively.
For two cities on the same river, if , then it is possible to travel by water from city to city .
The residents of Neverland have decided to build one-way shipping routes connecting city on the first river and city on the second river, but the direction is still to be determined.
If two cities can reach each other via waterways or shipping routes, then they are said to be connected. Among all cities, there are some sets of cities such that no pair of cities in the same set is connected. Please choose a direction for each shipping route so that, among all such sets, the maximum size of a set is as small as possible.
Input Format
The first line contains two positive integers .
The second line contains one positive integer .
The next lines each contain two positive integers , describing a one-way shipping route connecting city on the first river and city on the second river. The testdata guarantees that there are no duplicate unordered pairs .
Output Format
The first line contains one positive integer, the minimum possible value of the maximum set size.
The second line contains integers or . Here, means the direction is from city on the first river to city on the second river, and means the opposite.
If there are multiple valid solutions, output any one.
5 3
4
1 2
2 3
3 1
5 3
1
1 1 0 0
6 6
4
1 2
3 2
4 3
5 6
9
1 0 1 1
8 7
7
1 3
2 1
3 4
5 6
6 5
6 7
8 7
5
1 0 1 1 0 1 0
Hint
[Sample 1 Explanation]
An optimal solution can make every pair of cities connected, so the answer is .
[Constraints]
This problem uses bundled tests.
- Subtask 1 (20 pts): .
- Subtask 2 (30 pts): .
- Subtask 3 (60 pts): no additional constraints.
For of the testdata, , , .
[Notes]
This problem uses a self-written Special Judge. If you have any questions about it or want to hack, please PM the author or make a post.
[Source] COCI 2021-2022#5 Task 5 Usmjeravanje.
Translated by ChatGPT 5