This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |