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(){
    // freopen("input.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);

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

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

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

    printf("%d\n", ans.size() );
    for(auto i: ans)
        printf("%d ", i);
    puts("");
    return 0 ;
} 
Copy
Projects Rand()
GNU G++17
2001 ms
84.5 MB
Time Limit Exceeded