Under construction

Still being built. Things may change

Gods

Time limit2sMemory limit1024 MB

Summary
Split n gods into two lines so that no quarreling pair shares a line and no two attack segments cross, or print -1 if impossible.
Level

Hard8 of 10

Topics
Graph, DFS, Implementation
Solved
No attempts yet

Problem

At a feast in Asgard, the gods talked to each other. Under the influence of mead, they quarreled. A fight was about to break out, and the gods realized they wanted to fight only the ones they had argued with, and did not want to quarrel with any other god.

Odin, the cleverest god in Asgard, saw that it would be very convenient if the gods stood in two lines facing each other, so that no two gods who had quarreled were in the same line. Thor developed his father's idea and introduced the concept of an 'attack line'. An attack line is the segment connecting the positions of two gods who quarreled. Thor further proposed that it would be even more convenient if the attack lines of different gods did not intersect, because then the gods themselves would certainly not cross paths during the battle. All the gods approved. Only the positions remain to be taken, and then the fight can begin.

As an honored citizen of Midgard, you have the chance to help the gods. Write a program that splits the gods into two lines so that Thor's refinement holds.

Input

The first line contains nn (1≤n≤1051 \le n \le 10^5), the number of gods in Asgard. Each of the next nn lines contains ki+1k_i + 1 integers. The first integer is kik_i (1≤ki≤n1 \le k_i \le n), the number of gods who quarreled with god ii, followed by the numbers of those gods. If god ii quarreled with god jj, then god jj quarreled with god ii. The sum of all kik_i does not exceed 4×n4 \times n.

Output

If a solution exists, print two numbers mm and kk on the first line: the number of gods in the first line and the number of gods in the second line. On the next two lines, print the numbers of the gods in the first and second lines, from left to right. Otherwise, print −1-1.

Examples2

  1. Example 1

    Input
    4
    1 2
    2 1 3
    2 2 4
    1 3
    
    Expected output
    2 2
    1 3
    2 4
    
  2. Example 2

    Input
    3
    2 2 3
    2 3 1
    2 1 2
    
    Expected output
    -1