# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239831 | 2020-06-17T11:11:45 Z | MrRobot_28 | Alkemija (COCI18_alkemija) | C++17 | 170 ms | 12784 KB |
#include <bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; vector <vector <int> > num(n); vector <int> a(m); for(int i = 0; i < m; i++) { cin >> a[i]; a[i]--; } int k; cin >> k; vector <int> cnt(k); vector <vector <int> > vec1(k), vec2(k); vector <bool> used(k); vector <bool> used1(n); for(int i = 0; i < k; i++) { int l, r; cin >> l >> r; vec1[i].resize(l); vec2[i].resize(r); cnt[i] = l; for(int j = 0; j < l; j++) { cin >> vec1[i][j]; vec1[i][j]--; num[vec1[i][j]].push_back(i); } for(int j = 0; j < r; j++) { cin >> vec2[i][j]; vec2[i][j]--; } } queue <int> q; for(int i = 0; i < m; i++) { used1[a[i]] = true; for(int j = 0; j < num[a[i]].size(); j++) { int ind = num[a[i]][j]; cnt[ind]--; if(cnt[ind] == 0) { used[ind] = true; q.push(ind); } } } while(q.size() != 0) { int v = q.front(); q.pop(); for(int i = 0; i < vec2[v].size(); i++) { int to = vec2[v][i]; if(!used1[to]) { used1[to] = true; for(int j = 0; j < num[to].size(); j++) { int to1 = num[to][j]; cnt[to1]--; if(cnt[to1] == 0) { used[to1] = true; q.push(to1); } } } } } vector <int> ans; for(int i = 0; i < n; i++) { if(used1[i]) { ans.push_back(i); } } cout << ans.size() << "\n"; for(int i = 0; i < ans.size(); i++) { cout << ans[i] + 1 << " "; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 3576 KB | Output is correct |
2 | Correct | 59 ms | 4952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 111 ms | 7832 KB | Output is correct |
2 | Correct | 119 ms | 9076 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 158 ms | 11252 KB | Output is correct |
2 | Correct | 134 ms | 9112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 170 ms | 12784 KB | Output is correct |
2 | Correct | 151 ms | 12148 KB | Output is correct |