Submission #735849

# Submission time Handle Problem Language Result Execution time Memory
735849 2023-05-04T19:59:25 Z TAhmed33 Alkemija (COCI18_alkemija) C++
80 / 80
108 ms 9532 KB
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n, m;
	cin >> n >> m;
	queue <int> cur;
	bitset <100001> ok;
	while (m--) {
		int x; cin >> x; cur.push(x); ok[x] = 1;
	}
	int k; cin >> k;
	vector <int> in[n + 1];
	vector <int> out[k + 1];
	queue <int> unlocked;
	int needed[k + 1] = {};
	int pos = 1;
	while (k--) {
		int l, r;
		cin >> l >> r;
		needed[pos] = l;
		while (l--) {
			int x; cin >> x;
			in[x].push_back(pos);
		}
		while (r--) {
			int x; cin >> x;
			out[pos].push_back(x);
		}
		pos++;
	}
	while (!cur.empty()) {
		auto q = cur.front(); cur.pop();
		for (auto j : in[q]) {
			if (needed[j]) needed[j]--; 
			if (needed[j] == 0) {
				unlocked.push(j);
			}
		}
		while (!unlocked.empty()) {
			auto l = unlocked.front(); unlocked.pop();
			for (auto j : out[l]) {
				if (!ok[j]) {
					ok[j] = 1;
					cur.push(j);
				}
			}
		}
	}
	cout << ok.count() << '\n';
	for (int i = 1; i <= n; i++) if (ok[i]) cout << i << " ";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 2740 KB Output is correct
2 Correct 35 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 5652 KB Output is correct
2 Correct 100 ms 6496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 8040 KB Output is correct
2 Correct 83 ms 6932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 9532 KB Output is correct
2 Correct 97 ms 8908 KB Output is correct