# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143363 | 2019-08-13T19:57:03 Z | vladciuperceanu | Alkemija (COCI18_alkemija) | C++14 | 194 ms | 11092 KB |
#include <iostream> #include <deque> #include <vector> using namespace std; int n,m,k,i,j,x,f[100005],viz[100005]; deque<int> coada; vector<int> lista[100005]; struct reactie { int L; int R; int necunoscute; vector<int> Y; }; reactie w[100005]; int main() { cin >> n >> m; for (i=1; i<=m; i++) { cin >> x; f[x] = 1; } cin >> k; for (i=1; i<=k; i++) { cin >> w[i].L >> w[i].R; w[i].necunoscute = w[i].L; for (j=1; j<=w[i].L; j++) { cin >> x; lista[x].push_back(i); if (f[x] == 1) { w[i].necunoscute--; if (w[i].necunoscute == 0) { coada.push_back(i); viz[i] = 1; } } } for (j=1; j<=w[i].R; j++) { cin >> x; w[i].Y.push_back(x); } } while (!coada.empty()) { int reac = coada.front(); coada.pop_front(); for (i=0; i<w[reac].Y.size(); i++) { int elem = w[reac].Y[i]; if (f[elem] == 0) { f[elem] = 1; for (j=0; j<lista[elem].size(); j++) { int val = lista[elem][j]; if (viz[val] == 0) { w[val].necunoscute--; if (w[val].necunoscute == 0) { coada.push_back(val); viz[val] = 1; } } } } } } int sol = 0; for (i=1; i<=100000; i++) if (f[i] == 1) sol++; cout << sol << "\n"; for (i=1; i<=100000; i++) if (f[i] == 1) cout << i << " "; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 7780 KB | Output is correct |
2 | Correct | 74 ms | 8236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 132 ms | 9336 KB | Output is correct |
2 | Correct | 169 ms | 9720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 180 ms | 10488 KB | Output is correct |
2 | Correct | 160 ms | 9712 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 194 ms | 11092 KB | Output is correct |
2 | Correct | 179 ms | 10688 KB | Output is correct |