Submission #50082

# Submission time Handle Problem Language Result Execution time Memory
50082 2018-06-07T13:19:15 Z JustInCase Alkemija (COCI18_alkemija) C++17
80 / 80
83 ms 9500 KB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int32_t MAX_N = 1e5;
const int32_t MAX_K = 1e5;

bool have[MAX_N + 5];
int32_t cnt[MAX_K + 5];
vector< int32_t > operationsWith[MAX_N + 5], operations[MAX_K + 5];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int32_t n, m;
	cin >> n >> m;

	for(int32_t i = 0; i < m; i++) {
		int32_t x;
		cin >> x;
		have[x] = true;
	}

	int32_t k;
	cin >> k;
	
	queue< int32_t > ready;
	for(int32_t i = 0; i < k; i++) {
		int32_t l, r;
		cin >> l >> r;
			
		for(int32_t j = 0; j < l; j++) {
			int32_t x;
			cin >> x;
			operationsWith[x].push_back(i);

			if(!have[x]) {
				cnt[i]++;
			}
		}

		for(int32_t j = 0; j < r; j++) {
			int32_t x;
			cin >> x;
			operations[i].push_back(x);
		}

		if(cnt[i] == 0) {
			ready.push(i);
		}
	}

	while(!ready.empty()) {
		int32_t curr = ready.front();
		ready.pop();

		for(auto &i : operations[curr]) {
			if(!have[i]) {
				for(auto &j : operationsWith[i]) {
					cnt[j]--;
					if(cnt[j] == 0) {
						ready.push(j);
					}
				}
				have[i] = true;
			}
		}
	}

	int32_t ans = 0;
	for(int32_t i = 1; i <= n; i++) {
		if(have[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	for(int32_t i = 1; i <= n; i++) {
		if(have[i]) {
			cout << i << " ";
		}
	}
	cout << endl;
}

# 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 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6332 KB Output is correct
2 Correct 43 ms 6888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 7928 KB Output is correct
2 Correct 56 ms 8332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 9228 KB Output is correct
2 Correct 77 ms 9228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 9500 KB Output is correct
2 Correct 79 ms 9500 KB Output is correct