Source Code
/**
 * Prof.Nicola
**/
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define mp make_pair
#define F first
#define S second
#define REP(i,l,r) for(long long i=(l);i<(r);i++)
#define PER(i,l,r) for(long long i=(r)-1;i>=(l);i--)
const long dx[4]={1,0,-1,0},dz[4]={0,1,0,-1};
const long double pi=3.14159265359;
const long long mod=1e9+7;
long long p(long long x){while(x&(x-1)){x=x&(x-1);}return x;}
template<class T>void re(T&x){cin>>x;}
template<class T1,class T2> void re(pair<T1,T2>&x){re(x.first);re(x.second);}
template<class T>void re(vector<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void re(deque<T>&x){for(long i=0;i<x.size();i++){re(x[i]);}}
template<class T>void out(T x){cout<<x<<" ";}
template<class T1,class T2>void out(pair<T1,T2>x){out(x.first);out(x.second);cout<<endl;}
template<class T>void out(vector<T>x,long l=0,long r=0){if(!r){r=x.size();}for(long i=l;i<r;i++){out(x[i]);}cout<<endl;}
template<class T>void out(deque<T>x,long l=0,long r=0){if(!r){r=x.size();}for(long i=l;i<r;i++){out(x[i]);}cout<<endl;}
template<class T>T cross(complex<T>x,complex<T>z){return (conj(x)*z).imag();}
template<class T>T dot(complex<T>x,complex<T>z){return (conj(x)*z).real();}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n,m,q,x;
    cin>>n>>m;
    cin>>q;
    vector<long>winners(q),ans;
    vector<bool>win(1e6+1),lose(1e6+1);
    re(winners);
    REP(i,0,q){
        win[winners[i]-1]=true;
    }
    vector<vector<long> >v(n),proj(1e6+1),possible(1e6+1);
    REP(i,0,n){
        cin>>x;
        v[i].resize(x);
        re(v[i]);
        REP(j,0,x){
            proj[v[i][j]-1].push_back(i);
        }
    }
    REP(i,0,m){
        if(!win[i]){
            REP(j,0,proj[i].size()){
                lose[proj[i][j]]=true;
            }
        }
    }
    REP(i,0,q){
        REP(j,0,proj[winners[i]-1].size()){
            if(!lose[proj[winners[i]-1][j]]){
                possible[winners[i]-1].push_back(proj[winners[i]-1][j]);
            }
        }
        if(possible[winners[i]-1].empty()){
            continue;
        }
        if(possible[winners[i]-1].size()==1){
            ans.push_back(possible[winners[i]-1][0]);
        }
    }
    if(ans.empty()){
        cout<<0<<endl;
        return 0;
    }
    sort(ans.begin(),ans.end());
    x=1;
    REP(i,1,ans.size()){
        if(ans[i]!=ans[i-1]){
            x++;
        }
    }
    cout<<x<<endl;
    cout<<ans[0]+1<<" ";
    REP(i,1,ans.size()){
        if(ans[i]!=ans[i-1]){
            cout<<ans[i]+1<<" ";
        }
    }
    cout<<endl;
    return 0;
}
Copy
Projects Rainbow
GNU G++17
1358 ms
166.3 MB
Accepted