#K9771. Team Formation

    ID: 39104 Type: Default 1000ms 256MiB

Team Formation

Team Formation

You are given an integer NN representing the number of students and an integer KK representing the team size. Each student is assigned a unique number from 11 to NN. For each student, you are provided a list of preferred teammates. A student ii (with 1iN1 \leq i \leq N) prefers student jj if jj appears in ii's list. Your task is to determine whether there exists a team consisting of exactly KK 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 [1,N][1, N], and the input guarantees that students are numbered starting at 11.

inputFormat

The first line contains two space-separated integers NN and KK.
Each of the next NN lines contains a space-separated list of integers, representing the preferred teammates for the corresponding student ii (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 KK students satisfying the condition; otherwise, output "NO".## sample

4 3
2 3
1 3
1 2
1 2
YES