Source Code
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <stack>
#include <map>
#include <math.h>
#include <cmath>
#include <string.h>
#include <numeric>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define all(x) (x).begin() , (x).end()
#define allR(x) (x).rbegin() , (x).rend()
#define pb push_back
const int N = 2e5+5, M=1e6+1, NN=1e8 , MX = 1e6+1;
const ll MXL=1e18 , MOD = 1e9 + 7 ;
int a[N], b[N];
int main(){
    // freopen("input.txt", "r", stdin);
    int n, m, sz=0;
    scanf("%d%d", &n, &m);
    int par;
    vector<int> team, ans;
    vector<pair<int,vector<int>>> v;
    map<int,int> mp, won;
    v.resize(n);
    scanf("%d", &par);
    while ( par-- ){
        int x;
        scanf("%d", &x);
        won[x]++;
    }
    for(int i=0 ; i<n ; i++){
        int q;
        scanf("%d", &q);
        team.clear();
        bool flag=0;
        for(int i=0 ; i<q ; i++){
            int x;
            scanf("%d", &x);
            if(!won[x])
                flag=1;
            team.pb(x);
        }
        if(!flag){
            v.pb({i+1, team});
            for(int i=0 ; i<q ; i++ )
                mp[team[i]]++;
        }
    }
    // for(int i=0 ; i<v.size() ; i++)
    //     for(int j=0 ; j<v[i].second.size(); j++)
    //         mp[v[i].second[j]]++;


    for(int i=0 ; i<v.size() ; i++){
        bool flag=0;
        for(int j=0 ; j<v[i].second.size(); j++){
            if(mp[v[i].second[j]]==1)
                flag=1;
        }
        if( flag )
            ans.pb(v[i].first);
    }

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