# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143311 | 2019-08-13T15:32:52 Z | nicolaalexandra | Alkemija (COCI18_alkemija) | C++14 | 196 ms | 11000 KB |
#include <iostream> #include <vector> #include <deque> #define DIM 100010 using namespace std; //ifstream fin ("date.in"); //ofstream fout ("date.out"); vector <int> r[DIM],L[DIM]; deque <int> c; int f[DIM],cnt[DIM]; int n,m,i,j,nr1,nr2,x,k; 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>>nr1>>nr2; for (j=1;j<=nr1;j++){ cin>>x; r[x].push_back(i); /// tin minte dint ce reactie face parte if (!f[x]) cnt[i]++; /// cate elemente mai trebuie adaugate ca sa pot forma reactia } for (j=1;j<=nr2;j++){ cin>>x; L[i].push_back(x); }} /// mai intai adaug intr o coada toate reactiile care deja se pot forma for (i=1;i<=k;i++) if (!cnt[i]) c.push_back(i); while (!c.empty()){ int x = c.front(); c.pop_front(); for (i=0;i<L[x].size();i++){ int nr = L[x][i]; if (!f[nr]){ f[nr] = 1; /// acum trebuie sa scad cnt ul pt fiecare reactie care il contine for (int j=0;j<r[nr].size();j++){ cnt[r[nr][j]]--; if (!cnt[r[nr][j]]) /// pot forma reactia c.push_back(r[nr][j]); }}}} int sol = 0; for (i=1;i<=n;i++) if (f[i]) sol++; cout<<sol<<"\n"; for (i=1;i<=n;i++) if (f[i]) cout<<i<<" "; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4984 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 4988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 6604 KB | Output is correct |
2 | Correct | 74 ms | 7204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 133 ms | 8720 KB | Output is correct |
2 | Correct | 146 ms | 9300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 181 ms | 10372 KB | Output is correct |
2 | Correct | 161 ms | 9592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 11000 KB | Output is correct |
2 | Correct | 185 ms | 10564 KB | Output is correct |