#P5533. [CCO 2019] Winter Driving
[CCO 2019] Winter Driving
Description
There are cities in the Northern White Empire, numbered from to . In city , there are residents.
There are roads, numbered from to . Road connects city and city , where . Each city is connected to at most 36 roads.
In winter, dangerous driving conditions cause the government to enforce traffic control, and all roads become one-way highways. That is, for each road , it becomes either a one-way highway from city to city , or a one-way highway from city to city .
Now, every resident wants to send holiday cards to all other citizens. However, to send a holiday card from city to city , it must be possible to travel from to using the highways, or .
Find the maximum total number of cards that can be delivered after all roads are converted into one-way highways.
Input Format
The first line contains a positive integer .
The second line contains positive integers to .
The third line contains positive integers to .
Output Format
One line containing a positive integer, the maximum total number of holiday cards that can be delivered.
4
3 3 4 1
1 2 1
67
Hint
Sample Explanation
One possible way is to convert:

into:

Then, each resident in city 3 can send 3 cards to city 3, 3 cards to city 2, 3 cards to city 1, and 1 card to city 4. So city 3 can send a total of 40 cards.
Similarly, city 2 can send 18 cards in total, city 1 can send 9 cards in total, and city 4 cannot send any cards.
So the answer is .
Constraints
For any valid ,
For any valid ,
Let be the number of roads connected to any city. .
Subtasks
Subtask 1 (20 points):
Subtask 2 (20 points): ,
Subtask 3 (20 points):
Subtask 4 (20 points): , and all roads connect to one city, i.e. this city has 36 connected cities, and each of those cities is connected to it by only one road.
Subtask 5 (20 points): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号