Submission #735849

#TimeUsernameProblemLanguageResultExecution timeMemory
735849TAhmed33Alkemija (COCI18_alkemija)C++98
80 / 80
108 ms9532 KiB
#include <bits/stdc++.h> using namespace std; int main () { int n, m; cin >> n >> m; queue <int> cur; bitset <100001> ok; while (m--) { int x; cin >> x; cur.push(x); ok[x] = 1; } int k; cin >> k; vector <int> in[n + 1]; vector <int> out[k + 1]; queue <int> unlocked; int needed[k + 1] = {}; int pos = 1; while (k--) { int l, r; cin >> l >> r; needed[pos] = l; while (l--) { int x; cin >> x; in[x].push_back(pos); } while (r--) { int x; cin >> x; out[pos].push_back(x); } pos++; } while (!cur.empty()) { auto q = cur.front(); cur.pop(); for (auto j : in[q]) { if (needed[j]) needed[j]--; if (needed[j] == 0) { unlocked.push(j); } } while (!unlocked.empty()) { auto l = unlocked.front(); unlocked.pop(); for (auto j : out[l]) { if (!ok[j]) { ok[j] = 1; cur.push(j); } } } } cout << ok.count() << '\n'; for (int i = 1; i <= n; i++) if (ok[i]) cout << i << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...