#P17004. [NWERC 2019] Firetrucks Are Red

[NWERC 2019] Firetrucks Are Red

Problem Description

Lily is fascinated by numbers. She believes the whole world revolves around them, and that everything is connected by numbers. Her friends, Alice, Bob, Charlie and Diane, are not convinced. But she gives them an example:

Alice lives in house number 25 on her street, but that is exactly > Bob’s age. Bob is born on June 4th, and Charlie was his parents’ > fourth child. Finally, Diane has five fingers on her left hand, which > happens to be the same as the number of toes that Bob has on his right > foot!

This shows that her friends are all connected—either directly or indirectly—by numbers. But she still has to convince her family as well as her coworkers.

Given a group of nn individuals, and a set of numbers that describe each individual, help Lily come up with a proof that shows that everyone in this group is either directly or indirectly connected by numbers, or determine that this is not possible.

Input Format

The input consists of:

  • One line with an integer nn (2n21052 \leq n \leq 2\cdot 10^5), the number of individuals in the group. The individuals are numbered from 11 to nn.

  • nn lines, describing the individuals in the group.

The iith such line starts with an integer mim_i (1mi21051 \leq m_i \leq 2\cdot 10^5), the number of numbers that describe individual ii.

The remainder of the line has mim_i distinct integers di,1,,di,mid_{i,1},\ldots,d_{i,m_i} (1di,j1091 \leq d_{i,j} \leq 10^9 for each jj), the set of numbers that describe individual ii.

It is guaranteed that the sum over all mim_i is at most 21052\cdot 10^5.

Output Format

Output a proof in the form of n1n-1 lines, each of which contains three integers pp, qq and rr, where pp and qq are distinct individuals that are both described by the number rr. Using only these relations, it must be possible to show that any pair of individuals in the group are connected either directly or indirectly.

If no such proof exists, output “impossible”. If there are multiple proofs, you may output any one of them.

6
2 17 10
1 5
2 10 22
3 17 22 9
2 17 8
3 9 22 16
impossible
6
2 17 10
2 5 10
2 10 22
3 17 22 9
2 17 8
3 9 22 16
1 3 10
2 3 10
3 4 22
4 5 17
4 6 9