You are a class teacher and you notice few things about your students:
Relationship between students is reflective
i.e. A hates B <=> B hates A
There are 3 kind of students
B
/
A - X
\
C
* X is a troublemaker here, (s)he does not get along with A, B and C.
* A, B and C don't have any conflict among them Q
/ | \
P -+- S
\ | /
R
* Each one of P, Q, R and S hates other three.You have to select a team for upcoming sports event. To avoid any conflict within the team, you decided to pick students such that there are no two students in the team who hate each other.
You had interview with each student and came up with list of non compatible students for each of your students.
You have to write an algorithm (focused on time-efficiency) to sort this data in rows So that you can select any one part from each row of output for your team (see examples).
Line 1 : N (Number of students, 0 < N <= 26)
Next 2*N lines; for each ith student of N :
Input:
> 3
> 1
> C
> 0
>
> 1
> A
Visualization:
Student | Does not like
--------+--------------
A | C
B |
C | A
C
/
A B
Output:
> A|C
> BInput:
> 8
> 2
> CE
> 1
> G
> 2
> AE
> 0
>
> 2
> AC
> 0
>
> 2
> BH
> 1
> G
Visualization:
Student | Does not like
--------+--------------
A | C, E
B | G
C | A, E
D |
E | A, C
F |
G | B, H
H | G
A B - G
/ \ \ D F
C - E H
Output:
> A|C|E
> BH|G
> D
> FInput:
> 9
> 0
>
> 1
> C
> 1
> B
> 5
> EFGHI
> 1
> D
> 1
> D
> 1
> D
> 1
> D
> 1
> D
Visualization:
Student | Does not like
--------+--------------
A |
B | C
C | B
D | E, F, G, H, I
E | D
F | D
G | D
H | D
I | D
F G
C |/
A / E - D - H
B |
I
Output:
> A
> B|C
> D|EFGHI