Submission #143221

# Submission time Handle Problem Language Result Execution time Memory
143221 2019-08-13T11:23:28 Z SeekingOblivion Alkemija (COCI18_alkemija) C++14
80 / 80
201 ms 11008 KB
#include<iostream>
#include<fstream>
#define fin cin
#define fout cout
#include<algorithm>
#include<queue>
using namespace std;
//ifstream fin("date.in");
//ofstream fout("date.out");
int poz,n,m,a,i,j,k,l,p,sol[100001],r,f[100001],nr[100001];
vector<int> rez[100001],v[100001];
queue<int> q;
int main(){
    fin>>n>>m;
    for(i=1;i<=m;i++){
        fin>>a;f[a]=1;
        sol[++p]=a;
    }
    fin>>k;
    for(i=1;i<=k;i++)
    {
        fin>>l>>r;
        for(j=1;j<=l;j++){
            fin>>a;
            if(f[a]==0){
                nr[i]++;
                v[a].push_back(i);
            }
        }
        for(j=1;j<=r;j++)
        {
            fin>>a;
            if(f[a]==0) rez[i].push_back(a);
        }
        if(nr[i]==0) q.push(i);
    }
    while(!q.empty()){
        poz=q.front();q.pop();
        for(auto it:rez[poz])
        if(f[it]==0){
            f[it]=1;sol[++p]=it;
            for(auto IT:v[it])
            {
                nr[IT]--;
                if(nr[IT]==0) q.push(IT);
            }
        }
    }
    sort(sol+1,sol+p+1);
    fout<<p<<"\n";
    for(i=1;i<=p;i++) fout<<sol[i]<<" ";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 6648 KB Output is correct
2 Correct 73 ms 7264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 8600 KB Output is correct
2 Correct 143 ms 9424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 10488 KB Output is correct
2 Correct 143 ms 7672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 11008 KB Output is correct
2 Correct 186 ms 10700 KB Output is correct