P4843 Clearing Ski Runs
Description
A ski resort is located on several mountains in the northwest of FJ Province.
From an aerial view, the ski resort can be seen as a directed acyclic graph. Each arc represents a slope (i.e., a ski run), and the direction of the arc represents the downhill direction of the slope.
Your team is responsible for regularly clearing the ski runs every week. You have a helicopter. In each flight, it can carry one person from the headquarters to land at some location in the ski resort, and then fly back to the headquarters. Starting from the landing location, this person can ski downhill along the slopes and clear the ski runs he passes through.
Since the cost of each flight is fixed, to minimize the cost, you want to know the minimum number of flights needed to complete the task of clearing all ski runs.
Input Format
The first line contains an integer $n$, representing the number of locations in the ski resort.
The next $n$ lines describe the slopes starting from locations $1$ to $n$. In the $i$-th line, the first number is $m_i$, followed by $m_i$ integers separated by spaces. Each integer $a_{i,j}$ is distinct, representing a slope from location $i$ down to location $a_{i,j}$.
Output Format
Output one integer in a single line, representing the minimum number of helicopter flights.
Explanation/Hint
#### Constraints
For $100\%$ of the testdata, $2 \le n \le 100$, $0 \le m_i < n$, and each location is connected to at least one slope.
Translated by ChatGPT 5