CF BUDDY
← Problems·

1949F · Dating

2200 · greedy, sortings, trees

Problem: You are the developer of a dating app which ignores gender completely. The app has nn users, indexed from 11 to nn. Each user's profile features a list of the activities they enjoy doing. There are mm possible activities, indexed from 11 to mm.

A match between two users is good if they share at least one activity and, at the same time, both of them like at least one activity that the other user does not like.

Find a good match if it exists.

Input Format: The first line contains two integers nn and mm (2n2000002 \leq n \leq 200\,000, 1m1061 \leq m \leq 10^6) — the number of users and the number of activities.

Each of the following nn lines contains a number kik_i (0kim0 \leq k_i \leq m) — the number of activities that user ii likes — followed by kik_i distinct integers from 11 to mm — the activities user ii likes.

It is guaranteed that k1+k2++knk_1+k_2+\cdots+k_n does not exceed 10610^6.

Output Format: Print YES\texttt{YES} if a good match exists. Otherwise, print NO\texttt{NO}.

If a good match exists, on the next line print two integers — the indexes of two users that make a match.

Note: In the first sample, users 11 and 33 form a match, because they share activity 11, and, furthermore, user 33 likes activity 55 (which user 11 does not like) and user 11 likes activity 44 (which user 33 does not like). Note that users 11 and 22, as well as users 22 and 33, do not form a match, as there is no activity that users 11 or 33 like, and user 22 doesn't like.

Sample Cases

Case 1

Input

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

Output

YES
3 1

Case 2

Input

3 3
1 1
1 2
3 2 3 1

Output

NO

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback