Submission #98225

# Submission time Handle Problem Language Result Execution time Memory
98225 2019-02-21T15:31:50 Z dalgerok Alkemija (COCI18_alkemija) C++17
80 / 80
93 ms 11344 KB
#include<bits/stdc++.h>
using namespace std;



const int N = 1e5 + 5;



int n, m, k, x, cnt[N];
bool used[N];
vector < int > q[N], s[N];


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> x;
        used[x] = true;
    }
    cin >> k;
    queue < int > qq;
    for(int i = 1; i <= k; i++){
        int l, r;
        cin >> l >> r;
        for(int j = 1; j <= l; j++){
            cin >> x;
            q[x].push_back(i);
            if(!used[x]){
                cnt[i] += 1;
            }
        }
        for(int j = 1; j <= r; j++){
            cin >> x;
            s[i].push_back(x);
        }
        if(cnt[i] == 0){
            qq.push(i);
        }
    }
    while(!qq.empty()){
        int v = qq.front();
        qq.pop();
        for(int to : s[v]){
            if(!used[to]){
                used[to] = true;
                for(auto it : q[to]){
                    if(--cnt[it] == 0){
                        qq.push(it);
                    }
                }
            }
        }
    }
    vector < int > ans;
    for(int i = 1; i <= n; i++){
        if(used[i]){
            ans.push_back(i);
        }
    }
    cout << (int)ans.size() << "\n";
    for(auto it : ans){
        cout << it << " ";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6628 KB Output is correct
2 Correct 40 ms 7288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9056 KB Output is correct
2 Correct 65 ms 9504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 10460 KB Output is correct
2 Correct 65 ms 9864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 11344 KB Output is correct
2 Correct 93 ms 10572 KB Output is correct