# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145096 | 2019-08-18T18:50:18 Z | MihneaHedea | Alkemija (COCI18_alkemija) | C++14 | 203 ms | 11660 KB |
#include <iostream> #include <deque> #include <vector> #include <bitset> using namespace std; struct reactie { int L; int R; int necunoscute; vector<int> Y; }; reactie e[100010]; deque<int> coada; vector<int> Lista[100010]; int n, m, i, v, k, j, x, nod, ec, reactie, sol; bitset<100010> f, viz; int main () { cin>>n>>m; for (i=1;i<=m;i++) { cin>>v; f[v] = 1; } cin>>k; for (i=1;i<=k;i++) { cin>>e[i].L>>e[i].R; e[i].necunoscute = e[i].L; for (j=1;j<=e[i].L;j++) { cin>>x; Lista[x].push_back(i); if (f[x] == 1) { e[i].necunoscute--; if (e[i].necunoscute == 0) { coada.push_back(i); viz[i] = 1; } } } for (j=1;j<=e[i].R;j++) { cin>>x; e[i].Y.push_back(x); } } while (!coada.empty()) { nod = coada.front(); coada.pop_front(); for (i=0;i<e[nod].Y.size();i++) { ec = e[nod].Y[i]; if (f[ec] == 0) { f[ec] = 1; for (j=0;j<Lista[ec].size();j++) { reactie = Lista[ec][j]; if (viz[reactie] == 0) { e[reactie].necunoscute--; if (e[reactie].necunoscute == 0) { coada.push_back(reactie); viz[reactie] = 1; } } } } } } 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 | 6520 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 | 9 ms | 6648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 6648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 7928 KB | Output is correct |
2 | Correct | 73 ms | 8572 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 9720 KB | Output is correct |
2 | Correct | 145 ms | 10616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 182 ms | 10872 KB | Output is correct |
2 | Correct | 162 ms | 10780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 203 ms | 11640 KB | Output is correct |
2 | Correct | 181 ms | 11660 KB | Output is correct |