Submission #333509

#TimeUsernameProblemLanguageResultExecution timeMemory
333509JovanK26Alkemija (COCI18_alkemija)C++14
80 / 80
71 ms10732 KiB
#include <bits/stdc++.h> using namespace std; int n,m,x,k,l,r; int cnt=0; int nr[100001]; bool is[100001]; int rez[100001]; vector<int> v1[100001]; vector<int> v2[100001]; queue<int> q; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for(int i=1;i<=m;i++) { cin >> x; is[x]=1; rez[++cnt]=x; } cin >> k; for(int i=1;i<=k;i++) { cin >> l >> r; for(int j=1;j<=l;j++) { cin >> x; if(!is[x]) { nr[i]++; v1[x].push_back(i); } } for(int j=1;j<=r;j++) { cin >> x; if(!is[x]) { v2[i].push_back(x); } } if(!nr[i])q.push(i); } while(!q.empty()) { int cur=q.front(); q.pop(); for(auto node : v2[cur]) { if(!is[node]) { is[node]=1; rez[++cnt]=node; for(auto react : v1[node]) { nr[react]--; if(!nr[react])q.push(react); } } } } sort(rez+1,rez+cnt+1); cout << cnt <<'\n'; for(int i=1;i<=cnt;i++) { cout << rez[i]<<' '; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...