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>
#include <unordered_set>
#include <unordered_map>
#define endl "\n"
#define debug(x) cout << "DEBUG" << x << ": "
#define fastimize() ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define all(v) (v.begin()), (v.end())
#define endof(v) v[v.size() - 1]
#define setall(a, val) memset(a, val, sizeof a)
#define range(v, s, e) (v.begin() + s), (v.begin() + e)
#define ll long long
const ll MOD = 1e9 + 7;
const ll N = 1e6 + 1;
const ll M = 30;
using namespace std;
bool have[N];
bool used[N];
struct Reaction {
vector<int> to;
vector<bool> need;
Reaction() : to(vector<int>(0)), need(vector<bool>(0)) {}
};
int main() {
fastimize();
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
have[x] = true;
}
int k;
cin >> k;
vector<Reaction> reactions(k);
for (int i = 0; i < k; i++) {
int l, r;
cin >> l >> r;
vector<int> x(l), y(r);
reactions[i].need = vector<bool>(n + 1, false);
for (int j = 0; j < l; j++) {
cin >> x[j];
if (!have[x[j]])
reactions[i].need[x[j]] = !have[x[j]];
}
for (int j = 0; j < r; j++)
cin >> y[j];
reactions[i].to = y;
}
bool flag = true;
while (flag) {
flag = false;
for (int i = 0; i < k; i++) {
if (!used[i]) {
for (int j = 0; j < reactions[i].need.size(); j++) {
if (have[reactions[i].need[j]])
reactions[i].need[j] = false;
}
if (reactions[i].need != vector<bool>(n + 1, false))
break;
flag = true;
used[i] = true;
for (int x : reactions[i].to)
have[x] = true;
break;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
ans += have[i];
cout << ans << endl;
for (int i = 1; i <= n; i++)
if (have[i])
cout << i << ' ';
cout << endl;
}
Compilation message (stderr)
alkemija.cpp: In function 'int main()':
alkemija.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < reactions[i].need.size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |