#K9771. Team Formation
Team Formation
Team Formation
You are given an integer representing the number of students and an integer representing the team size. Each student is assigned a unique number from to . For each student, you are provided a list of preferred teammates. A student (with ) prefers student if appears in 's list. Your task is to determine whether there exists a team consisting of exactly students such that for every pair of distinct students in the team, each student prefers the other. If such a team exists, print "YES"; otherwise, print "NO".
Note: The preference list for each student may contain any number of distinct student numbers in the range , and the input guarantees that students are numbered starting at .
inputFormat
The first line contains two space-separated integers and .
Each of the next lines contains a space-separated list of integers, representing the preferred teammates for the corresponding student (1-indexed). There is at least one integer in each list.
outputFormat
Output a single line containing the string "YES" if there exists a valid team of students satisfying the condition; otherwise, output "NO".## sample
4 3
2 3
1 3
1 2
1 2
YES