Baltic Olympiad in Informatics: 2016 Day 1, Problem 1
A company of
Each employee has a list of bosses they will accept. In addition, all employees must be assigned a salary. The salary must be a positive integer, and the salary of each boss must be larger than the sum of salaries of their immediate subordinates.
Your task is to structure the company so that all above conditions hold, and the sum of all the salaries is as small as possible.
Constraints
Subtask 1 [22%]
Subtask 2 [45%]
Subtask 3 [33%]
Input Specification
The first input line contains an integer
After this, the input contains
Output Specification
You should output the lowest total salary among all valid restructurings. You can assume that at least one solution exists.
Sample Input
4
1 4
3 1 3 4
2 1 2
1 3
Sample Output
8
Comments