P28536 [洛谷] Team Division in Xiao Z's Game
提高+
题目描述

Problem Description

Tired of loneliness, Xiao Z is planning to host a DOTA tournament. To ensure that everyone in the ACM class participates, he has specially created a DOTA map that supports any number of players against any number of others.

The challenge now is how to divide everyone into two teams. Xiao Z's approach is for each person to list the classmates they are willing to team up with, and then he will divide everyone into two teams according to the following rules:

For any student A, all the people on the same team as student A must be classmates that student A is willing to team up with.

Xiao Z wants the difference in the number of people between the two teams to be as small as possible. If such a division does not exist, the output should be No solution.

Input Format

The first line contains \( N \), indicating the total number of students.

The next \( N \) lines, from line 2 to line \( N+1 \), each represent the list of trusted classmates for that student, ending with a \( 0 \).

Output Format

One line. If a solution exists, output the number of people in the two teams, with the smaller number first; if no solution exists, output No solution.

Sample Input and Output

Sample Input #1

5
3 4 5 0
1 3 5 0
2 1 4 5 0
2 3 5 0
1 2 3 4 0

Sample Output #1

No solution

Sample Input #2

5
2 3 5 0
1 4 5 3 0
1 2 5 0
1 2 3 0
4 3 2 1 0

Sample Output #2

2 3

Notes

For 30% of the data, \( N \leq 10 \);

For 100% of the data, \( N \leq 2000 \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 3 4 5 0 1 3 5 0 2 1 4 5 0 2 3 5 0 1 2 3 4 0
样例输出
No solution