#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 aa supports school bb, it does not necessarily mean school bb supports school aa). 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

  1. 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.
  2. 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 nn, representing the total number of schools connected to the network. The next nn lines describe the schools each school supports, i.e., the (i+1)(i+1)-th line lists the school codes supported by the ii-th school, ending with a 00.
If a school does not support any other schools, the corresponding line will only contain a 00. 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

2n1002 \le n \le 100.