Submission #333509

# Submission time Handle Problem Language Result Execution time Memory
333509 2020-12-06T16:01:02 Z JovanK26 Alkemija (COCI18_alkemija) C++14
80 / 80
71 ms 10732 KB
#include <bits/stdc++.h>

using namespace std;
int n,m,x,k,l,r;
int cnt=0;
int nr[100001];
bool is[100001];
int rez[100001];
vector<int> v1[100001];
vector<int> v2[100001];
queue<int> q;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i=1;i<=m;i++)
    {
       cin >> x;
       is[x]=1;
       rez[++cnt]=x;
    }
    cin >> k;
    for(int i=1;i<=k;i++)
    {
        cin >> l >> r;
        for(int j=1;j<=l;j++)
        {
            cin >> x;
            if(!is[x])
            {
                nr[i]++;
                v1[x].push_back(i);
            }
        }
        for(int j=1;j<=r;j++)
        {
            cin >> x;
            if(!is[x])
            {
                v2[i].push_back(x);
            }
        }
        if(!nr[i])q.push(i);
    }
    while(!q.empty())
    {
        int cur=q.front();
        q.pop();
        for(auto node : v2[cur])
        {
            if(!is[node])
            {
                is[node]=1;
                rez[++cnt]=node;
                for(auto react : v1[node])
                {
                    nr[react]--;
                    if(!nr[react])q.push(react);
                }
            }
        }
    }
    sort(rez+1,rez+cnt+1);
    cout << cnt <<'\n';
    for(int i=1;i<=cnt;i++)
    {
        cout << rez[i]<<' ';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6636 KB Output is correct
2 Correct 33 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8428 KB Output is correct
2 Correct 51 ms 9344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 10348 KB Output is correct
2 Correct 40 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 10732 KB Output is correct
2 Correct 65 ms 10476 KB Output is correct