How Many Dependencies?

In this problem you will need to find out which task has the most number of dependencies. A task A depends on another task B if B is a direct or indirect dependency of A. For example, if A depends on B and B depends on C, then A has two dependencies, one direct and one indirect. You can assume there will be no cyclic dependencies in the input. Input The input consists of a set of scenarios. Each scenario begins with one integer N, 0 < N ≤ 100, in a line indicating how many tasks this scenario contains. Then there will be N lines, one for each task. Each line will contain an integer 0 ≤ T ≤ N − 1, the number of direct dependencies of that task, plus T integers, the identifiers of that dependencies. Tasks are numbered from 1 to N. The input ends with a scenario where N = 0. Output For each scenario, print the number of the task with the greatest number of dependencies alone in a line. If there are ties, show the task with the lowest identifier. Sample Input 3 12 13 0 4 224 0 224 0 0 Sample Output 1 1