90分求助
查看原帖
90分求助
366937
too_simple楼主2023/2/16 21:21
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1e6 + 6;

int t, n;
struct node {
    int k, id;
    vector<int> v;
    bool operator<(const node &jq) const {
        return k < jq.k;
    }
}p[N];
int vis[N], cnt[N];

void init() {
    for(int i = 1; i <= n; ++ i) p[i].v.clear(), vis[i] = 0;
}

void work() {
    init();
    for(int i = 1; i <= n; ++ i) {
        cin >> p[i].k;
        p[i].id = i;
        for(int j = 1; j <= p[i].k; ++ j) {
            int x;
            cin >> x;
            p[i].v.push_back(x);
        }
    }
    sort(p + 1, p + 1 + n);
    for(int i = 1; i <= n; ++ i) {
        int id = p[i].id;
        if(!p[i].k) continue;
        for(int j = 0; j < p[i].k; ++ j) {
            cnt[vis[p[i].v[j]]] ++;
        }
        for(int j = 0; j < p[i].k; ++ j) {
            int g = vis[p[i].v[j]];
            if(g && cnt[g] < p[g].k) {
                puts("YES");
                cout << p[g].id << " " << p[i].id << endl;
                return ;
            }
        }
        for(int j = 0; j < p[i].k; ++ j) {
            cnt[vis[p[i].v[j]]] --;
            vis[p[i].v[j]] = i;
        }
    }
    puts("NO");
    return ;
}

int main() {
    
    cin >> t;
    
    while(t -- ) {
        cin >> n;
        work();
    }
    
    return 0;
}
2023/2/16 21:21
加载中...