Submission #143994

# Submission time Handle Problem Language Result Execution time Memory
143994 2019-08-15T14:57:13 Z AldeaDanut Alkemija (COCI18_alkemija) C++14
80 / 80
199 ms 12000 KB
#include <iostream>
#include <vector>
#include <deque>
#include <bitset>
using namespace std;

struct reactie{
    int l,r;
    int nec;
    vector<int> p;
};

int n,m,k,i,j,elem,R,cnt,sol;
reactie r[100001];
bitset <100001> f;
deque <int> c;
vector <int> lista[100001];

int main(){
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>j;
        f[j]=1;
        sol++;
    }

    cin>>k;
    for(i=1;i<=k;i++){
        cin>>r[i].l>>r[i].r;
        r[i].nec=r[i].l;
        for(j=1;j<=r[i].l;j++){
            cin>>elem;
            if(f[elem])
                r[i].nec--;
            lista[elem].push_back(i);
        }
        for(j=1;j<=r[i].r;j++){
            cin>>elem;
            r[i].p.push_back(elem);
        }

        if(r[i].nec==0)
            c.push_back(i);
    }

    while(!c.empty()){
        R=c.front();
        c.pop_front();

        for(i=0;i<r[R].r;i++){
            elem=r[R].p[i];

            if(f[elem]==0){
                f[elem]=1;
                sol++;

                cnt=lista[elem].size();
                for(j=0;j<cnt;j++){
                    r[lista[elem][j]].nec--;
                    if(r[lista[elem][j]].nec==0)
                        c.push_back(lista[elem][j]);
                }
            }
        }
    }

    cout<<sol<<"\n";
    for(i=1;i<=n;i++)
        if(f[i])
            cout<<i<<" ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 8048 KB Output is correct
2 Correct 75 ms 8624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 9996 KB Output is correct
2 Correct 152 ms 10580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 11720 KB Output is correct
2 Correct 161 ms 10748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 12000 KB Output is correct
2 Correct 186 ms 11520 KB Output is correct