#P4674. [BalticOI 2016] Bosses (day1)

[BalticOI 2016] Bosses (day1)

题目描述

A company of nn employees is due for a restructuring. In the resulting hierarchy,represented as a rooted tree, every node will be the boss of its children.

Each employee has a list of bosses they will accept. In addition, all employees mustbe assigned a salary. The salary must be a positive integer, and the salary of eachboss 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 sumof all the salaries is as small as possible.

输入格式

The first input line contains an integer nn : the number of employees. The employees are numbered 1,2,...,n1,2,...,n

.After this, the input contains nn lines that describe the preferences of the employees.The iith such line contains an integer kik_i , followed by a list of kik_i integers. The list consists of all employees that the iith employee accepts as their boss.

输出格式

You should output the lowest total salary among all valid restructurings. You can assume that at least one solution exists.

4
1 4
3 1 3 4
2 1 2
1 3

8

提示

Subtask 1 (22 points)

  • 2n102\leq n \leq 10

  • i=1nki20\sum^n_{i=1}k_i\leq 20

Subtask 2 (45 points)

  • 2n1002\leq n \leq 100

  • i=1nki200\sum^n_{i=1}k_i\leq 200

Subtask 3 (33 points)

  • 2n50002\leq n \leq 5000

  • i=1nki10000\sum^n_{i=1}k_i\leq 10000