-->
当前位置:首页 > 题库

PROGRAMMING:Grouping problem

Luz5年前 (2021-05-10)题库488
An algorithm is designed to solve the following problems
There are n people (2 < = n < = 100), and they are divided into two non empty groups, which meet the following rules:
one Everyone was divided into a group
two People in the same group know each other
three The number of members of the two groups should be as close as possible
[test case: Hao Zongyin, IOT engineering level 16]
###Input format:
Enter n in the first line, representing n people, numbered 1 ~ n
Then n lines, each line to enter a number, ending with 0, the I line that the number of people I know who.
For example, the first behavior 3 4 5 0 means that the person numbered 1 knows the person numbered 3, 4 and 5.
###Output format:
Output "no solution" without solution, otherwise output two groups of people. At the beginning of each group, output the number x of this group first, and then output the number of X person from small to large. Note that the group with the smaller number of the first person outputs first.
For example, if the first group is 1.35, the second group is 2.4, and 1 is smaller than 2, then the first group is output first, and then the second group is output.
###Input example:
Here is a set of inputs. For example:
```in
five
3 4 5 0
1 3 5 0
2 1 4 5 0
2 3 5 0
1 2 3 4 0
```
###Output example:
The corresponding output is given here. For example:
```out
No solution
```







answer:If there is no answer, please comment