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 = 1e6, M=1e6+1, NN=1e8 , MX = 1e6+1;
const ll MXL=1e18 , MOD = 1e9 + 7 ;
int a[N];
map<int, bool> won;
map<int,int> mp;
vector<vector<int>> v;
vector<int> pos, ans;
int main(){
    // freopen("input.txt", "r", stdin);
    int n, m, q;
    cin >> n>> m >> q;
    v.resize(n);
    while ( q-- ){
        int x;
        scanf("%d" , &x );
        won[x]=1;
    }
    for(int i=0 ; i<n ; i++ ){
        scanf("%d" , &q );
        int cnt=0;
        for(int j=0,x ; j<q ; j++ ){
            scanf("%d", &x );
            v[i].pb(x);
            if(won[x])
                cnt++;
        }
        if( cnt == q )
            pos.pb(i);
    }
    for(int i=0 ; i<pos.size() ; i++ ){
        int sz = v[pos[i]].size();
        for(int j=0 ; j<sz ; j++ ){
            int winner= v[pos[i]][j];
            mp[winner]++;
        }
    }
    for(int i=0 ; i<pos.size() ; i++ ){
        int cnt=0, sz=v[pos[i]].size();
        for(int j=0 ; j<sz ; j++ ){
            if(mp.count(v[pos[i]][j]) && mp[  v[ pos[i] ] [j]  ] == 1 ){
                cnt++;
                break;
            }
        }
        if(cnt)
            ans.pb(pos[i]+1);
    }
    sort(all(ans));
    printf("%d\n", ans.size() );
    for(auto i: ans)
        printf("%d ", i);
    return 0 ;
}
Copy
Projects Rand()
GNU G++17
2102 ms
63.8 MB
Time Limit Exceeded