This page is still under construction.

Parts of this page are still being built. What you see may change.

Team Them Up

Time limit1sMemory limit128 MB

Summary
Split N people into two teams where teammates must mutually know each other, minimizing the size difference, and report the two team sizes.
Level

Medium7 of 10

Topics
Graph, DFS, Dynamic programming, Brute force
Solved
No attempts yet

Problem

Divide a group of people into exactly two teams so that:

  • everyone belongs to exactly one team;
  • each team has at least one member;
  • inside a team, every person knows every other member of that team;
  • the two teams are as close in size as possible.

Acquaintance is not necessarily mutual: person aa may know person bb while bb does not know aa. Two people may be placed on the same team only if they know each other in both directions.

If it is impossible to split everyone into two such teams, report that no valid division exists.

Input

The people are numbered with distinct integers from 11 to NN.

The first line contains one integer NN (2≤N≤1002 \le N \le 100) — the number of people. Each of the next NN lines describes one person in increasing order of their number. The ii-th of these lines lists the distinct numbers AijA_{ij} (1≤Aij≤N1 \le A_{ij} \le N, Aij≠iA_{ij} \ne i) of the people that person ii knows, separated by spaces and terminated by a single 00.

Output

If no valid division exists, print a single line containing No solution.

Otherwise the closest-possible split has a unique pair of team sizes. Print these two sizes on one line separated by a space: first the size of the smaller team, then the size of the larger team (if the two teams are equal, print that size twice).

Examples2

  1. Example 1

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

    Input
    5
    3 4 5 0
    1 3 5 0
    2 1 4 5 0
    2 3 5 0
    1 2 3 4 0
    
    Expected output
    No solution