이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |