Source Code
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define pb push_back
const int N=1e6+1;
int mp[N];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);

    vector<pair<int,vector<int>>> v;
    map<int,bool> won;

    int par;
    scanf("%d", &par);
    while ( par-- ){
        int x;
        scanf("%d", &x);
        won[x]=1;
    }
    v.resize(n);
    for(int i=0 ; i<n ; i++){
        int q, x;
        scanf("%d", &q);
        vector<int> team;
        team.resize(q);
        bool flag=0;
        for(int i=0; i<q ; i++){
            scanf("%d", &x);
            if(!won[x])
                flag=1;
            team.pb(x);
        }
        if(!flag){
            v.pb({i+1, team});
            for( auto k : team )
                mp[k]++;
        }
    }

    vector<int> ans;
    for(int i=0 ; i<v.size() ; i++){
        for(auto j: v[i].second ){
            if(mp[j]==1){
                ans.pb(v[i].first);
                break;
            }
        }
    }

    printf("%d\n", ans.size() );
    for(auto i: ans)
        printf("%d ", i);
    puts("");

    return 0 ;
}
Copy
Projects Rand()
GNU G++17
2104 ms
110.4 MB
Time Limit Exceeded