Dating

시간 제한3초메모리 제한2048 MB

요약
각 사용자가 좋아하는 활동 집합이 주어질 때, 공통 활동이 있으면서 서로가 상대만 좋아하는 활동을 하나씩 가진 두 사용자를 찾아 출력한다.
난이도

보통10점 중 7점

유형
해시맵, 정렬, 그리디, 배열
정답자
아직 제출이 없습니다

문제

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.

입력

The first line contains two integers nn and mm (2≤n≤200,0002 ≤ n ≤ 200\\, 000, 1≤m≤1061 ≤ m ≤ 10^6) — the number of users and the number of activities.

Each of the following nn lines contains a number k_ik\_i (0≤k_i≤m0 ≤ k\_i ≤ m) — the number of activities that user ii likes — followed by k_ik\_i distinct integers from 11 to mm — the activities user ii likes.

It is guaranteed that k_1+k_2+⋯+k_nk\_1 + k\_2 + \cdots + k\_n does not exceed 10610^6.

출력

Print YES if a good match exists. Otherwise, print NO.

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

예제2

  1. 예제 1

    입력
    3 5
    3 1 2 4
    5 1 2 3 4 5
    2 1 5
    
    예상 출력
    YES
    3 1
    
  2. 예제 2

    입력
    3 3
    1 1
    1 2
    3 2 3 1
    
    예상 출력
    NO