Submission #156577

#TimeUsernameProblemLanguageResultExecution timeMemory
156577heonAlkemija (COCI18_alkemija)C++17
80 / 80
83 ms11608 KiB
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <queue> #include <bitset> #include <stack> #include <iomanip> using namespace std; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef vector <int> vi; typedef pair<int,int> ii; typedef long long ll; typedef long double ld; const int mod = 1e9 + 7; const ll inf = 3e18 + 5; int add(int a, int b) { return (a += b) < mod ? a : a - mod; } int mul(int a, int b) { return 1LL * a * b % mod; } const int maxn = 1e5 + 5; vi g[maxn], cmp[maxn]; int deg[maxn], done[maxn], a[maxn]; vi res; void dfs(int u){ res.push_back(u); done[u] = 1; for(int v : g[u]){ if(--deg[v] == 0){ for(int y : cmp[v]){ if(!done[y]){ dfs(y); } } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ cin >> a[i]; } int k; cin >> k; for(int i = 0; i < k; i++){ int l, r; cin >> l >> r; for(int j = 0; j < l; j++){ int x; cin >> x; g[x].push_back(i); } for(int j = 0; j < r; j++){ int x; cin >> x; cmp[i].push_back(x); } deg[i] = l; } for(int i = 0; i < m; i++){ if(!done[a[i]]){ dfs(a[i]); } } cout << res.size() << "\n"; sort(all(res)); for(int x : res){ cout << x << " "; } }
#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...