#P3408. The Domino Principle

    ID: 2418 远端评测题 1000ms 64MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>Northeastern Europe 2002, Western Subregion

The Domino Principle

Description

There is a configuration of N domino stones that is to be beautifully destroyed. For each stone i in the given configuration, we know the set Di of the stones that will fall at time t+1 (if they have not fallen before) if the stone i falls at time t.

Write a program to determine which stone should be pushed to fall at the time 0 to achieve complete destruction of the configuration that takes the longest possible time.

Input

The first line of the input contains the number of stones N in the configuration (1≤N≤1000). Next N lines describe sets Di (1≤iN). Each of these lines contains first the potency of the set Di and then the numbers of stones in the set separated by one or more spaces.

Output

The first line of the output must contain the time of fall of the last stone in the configuration, and the second line - the number of the stone that should be pushed first. If the maximal time can be achieved starting from several initial stones, output the maximal possible number. If the configuration can’t be destroyed completely, the first and only line of the file must contain the word ‘impossible’.

3
2 2 3
1 3
0
1
1

Source

Northeastern Europe 2002, Western Subregion