#include using namespace std; using ll = long long; using ld = long double; int main(){ ll n,m; cin >> n >> m; vector colors(m); vector> to_sort; vector> data(n+1); for(ll i = 0; i < n; i++){ ll size; cin >> size; pair record(size,i+1); to_sort.push_back(record); for(ll j = 0; j < size; j++){ ll hobby; cin >> hobby; data[i+1].push_back(hobby-1); } } sort(to_sort.begin(),to_sort.end()); reverse(to_sort.begin(),to_sort.end()); vector position_in_sorted_order(n+1); for(ll i = 0; i < to_sort.size(); i++){ ll person = to_sort[i].second; position_in_sorted_order[person] = i; } position_in_sorted_order[0] = -1; ll pos = 0; bool no_match = true; while(pos < to_sort.size()){ ll person = to_sort[pos].second; //check whether we are overwriting only one color ll color = -1; bool found = false; for(int i = 0; i < data[person].size(); i++){ ll hobby = data[person][i]; if(color == -1){ color = colors[hobby]; } if(color != colors[hobby]){ found = true; break; } } if(found){ //find the match int newest_outlier = 0; for(int i = 0; i < data[person].size(); i++){ ll hobby = data[person][i]; if(position_in_sorted_order[newest_outlier] < position_in_sorted_order[colors[hobby]]){ newest_outlier = colors[hobby]; } } cout << "YES" << endl << person << " " << newest_outlier << endl; no_match = false; break; } //it's all the same color, no match found, overwrite now for(int i = 0; i < data[person].size(); i++){ ll hobby = data[person][i]; colors[hobby] = person; } pos++; } if(no_match){ cout << "NO" << endl; } }