# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239011 | 2020-06-14T06:33:41 Z | NONAME | Alkemija (COCI18_alkemija) | C++17 | 81 ms | 15992 KB |
#include <iostream> #include <vector> #include <queue> #include <fstream> using namespace std; typedef long long ll; typedef pair <ll, ll> pll; const int N = 2e5 + 10; int n, m, ost[N], l[N], r[N]; bool mk[N], f[N]; vector <int> ps[N], v[N]; queue <int> q; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("in.txt", "r", stdin); cin >> n >> m; for (int i = 0; i < m; ++i) { int x; cin >> x; f[x] = 1; } cin >> m; for (int i = 0; i < m; ++i) { cin >> l[i] >> r[i]; ost[i] = l[i]; for (int j = 0; j < l[i]; ++j) { int x; cin >> x; ps[x].push_back(i); if (f[x]) --ost[i]; } if (!ost[i]) { q.push(i); mk[i] = 1; } for (int j = 0; j < r[i]; ++j) { int x; cin >> x; v[i].push_back(x); } } while (!q.empty()) { int u = q.front(); q.pop(); for (int i = 0; i < r[u]; ++i) { int x = v[u][i]; if (!f[x]) { f[x] = 1; for (int j = 0; j < ps[x].size(); ++j) { int p = ps[x][j]; if (mk[p]) continue; --ost[p]; if (!ost[p]) { q.push(p); mk[p] = 1; } } } } } int answer = 0; for (int i = 1; i <= n; ++i) answer += f[i]; cout << answer << "\n"; for (int i = 1; i <= n; ++i) if (f[i]) cout << i << " "; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 9728 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 11392 KB | Output is correct |
2 | Correct | 34 ms | 12024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 13688 KB | Output is correct |
2 | Correct | 58 ms | 14328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 15352 KB | Output is correct |
2 | Correct | 63 ms | 14436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 15992 KB | Output is correct |
2 | Correct | 69 ms | 15352 KB | Output is correct |