#Q95. 「一本通 3.5 练习 1」网络协议
「一本通 3.5 练习 1」网络协议
Description
Original Source: IOI 1996
Several schools are connected in a computer network. There are software support agreements between the schools. Each school has a list of schools it supports (if school supports school , it does not necessarily mean school supports school ). When a school receives new software, whether directly or via the network, it should immediately transmit the software to all the schools it supports. Therefore, to ensure that all schools connected to the network can use the new software, it is sufficient to provide the software to a select few schools.
Tasks
- Write a program that, based on the support agreements between schools (each school's support list), calculates the minimum number of schools that need to directly receive the new software so that it can be propagated to all schools via the network.
- If it is allowed to add new support relationships to the existing agreements, it is always possible to form a new agreement such that providing the new software to any single school will allow all other schools to receive it via the network. Calculate the minimum number of new support relationships that need to be added.
Input Format
The first line contains a positive integer , representing the total number of schools connected to the network.
The next lines describe the schools each school supports, i.e., the -th line lists the school codes supported by the -th school, ending with a .
If a school does not support any other schools, the corresponding line will only contain a . Multiple numbers in a line are separated by a single space.
Output Format
The output consists of two lines. The first line is a positive integer representing the solution to task a, and the second line is also a positive integer representing the solution to task b.
Sample 1
5
2 4 3 0
4 5 0
0
0
1 0
1
2
Constraints and Hints
.