Submission #239050

#TimeUsernameProblemLanguageResultExecution timeMemory
239050VEGAnnAlkemija (COCI18_alkemija)C++14
80 / 80
123 ms13944 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("fast-math") //#pragma GCC optimize("no-stack-protector") #define i2 array<int,2> #define PB push_back #define all(x) x.begin(),x.end() #define sz(x) ((int)x.size()) using namespace std; typedef long long ll; const int N = 100100; const ll OO = 1e18; const int md = int(1e9) + 7; vector<int> vc[N], who[N], fr[N]; queue<int> q; int n, m, k, cnt[N], ans = 0; bool mrk[N], was[N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #ifdef _LOCAL freopen("in.txt","r",stdin); #endif // _LOCAL cin >> n >> m; for (int i = 0; i < m; i++){ int x; cin >> x; mrk[x] = 1; ans++; } cin >> k; for (int i = 0; i < k; i++){ int L, R; cin >> L >> R; cnt[i] = L; for (int j = 0; j < L; j++){ int x; cin >> x; who[x].PB(i); fr[i].PB(x); if (mrk[x]) cnt[i]--; } if (cnt[i] == 0) q.push(i); for (int j = 0; j < R; j++) { int x; cin >> x; vc[i].PB(x); } } while (sz(q)){ int id = q.front(); q.pop(); for (int cr : vc[id]){ if (mrk[cr]) continue; mrk[cr] = 1; ans++; for (int nw : who[cr]){ cnt[nw]--; if (cnt[nw] == 0) q.push(nw); } } } cout << ans << '\n'; for (int i = 1; i <= n; i++) if (mrk[i]) cout << 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...