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;
    scanf("%d%d", &n, &m);

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

    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){
            v.pb({i+1, team});
            for( auto k : team )
                mp[k]++;
        }
    }

    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
2102 ms
45.0 MB
Time Limit Exceeded