Problem B
Subway
The Stockholm subway is very inefficient. The city does not look like it did when the current subway lines were built, meaning certain parts are highly overutilized while some lines are barely used.
Therefore, the city council has decided to rebuild the
subway. Currently, the system consists of
To minimize disruptions in the busy subway, the
reconstruction must be performed one track at a time. Every
weekend, a single track must be closed and a new track built.
This means that there will always be
Your task is to find a way of constructing the new subway network, such that these conditions hold. Your plan must use as few weekends as possible.
Input
The first line contains the integer
The next
Output
First, output the number of weekends
Grading
Your solution will be graded on a set of subtasks. A subtask will consist of multiple test cases. To get the points for a subtask, your solution must pass all test cases that are part of the subtask.
Subtask |
Score |
Constraints |
1 |
33 |
|
2 |
33 |
|
3 |
34 |
|
Sample Input 1 | Sample Output 1 |
---|---|
3 0 1 1 2 0 1 0 2 |
1 2 1 2 0 |
Sample Input 2 | Sample Output 2 |
---|---|
4 0 1 0 2 0 3 0 1 1 2 2 3 |
2 3 0 3 2 0 2 1 2 |