Submission #961847

# Submission time Handle Problem Language Result Execution time Memory
961847 2024-04-12T14:50:12 Z NK_ Povjerenstvo (COI22_povjerenstvo) C++17
0 / 100
3000 ms 80468 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())

template<class T> using V = vector<T>;
using vi = V<int>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M; cin >> N >> M;

	V<vi> adj(N), radj(N); vi out(N), dead(N);
	set<int> left; for(int i = 0; i < N; i++) left.insert(i);

	vi q; 
	auto rem = [&](int u) {
		left.erase(u);
		for(auto& v : radj[u]) if (!dead[v]) {
			out[v]--;
			if (out[v] == 0) q.pb(v);
		}
	};

	for(int i = 0; i < M; i++) {
		int u, v; cin >> u >> v; --u, --v;
		adj[u].pb(v);
		radj[v].pb(u); out[u]++;
	}

	for(int i = 0; i < N; i++) if (out[i] == 0) q.pb(i);

	vi ans;
	while(sz(left)) {
		int u; 
		if (sz(q)) { 
			u = q.back(); q.pop_back(); 
		} else u = *begin(left);

		// cout << u << endl;

		assert(!dead[u]);

		dead[u] = 1;
		for(auto& v : radj[u]) dead[v] = 1;

		rem(u); ans.pb(u);
		for(auto& v : radj[u]) rem(v);
	}

	cout << sz(ans) << nl;
	for(auto& x : ans) cout << x + 1 << " ";
	cout << nl;



	exit(0-0);
}
# Verdict Execution time Memory Grader output
1 Correct 239 ms 80468 KB Output is correct
2 Correct 254 ms 79968 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 157 ms 54144 KB Output is correct
5 Correct 198 ms 69680 KB Output is correct
6 Correct 263 ms 68488 KB Output is correct
7 Correct 200 ms 68380 KB Output is correct
8 Execution timed out 3047 ms 66600 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 230 ms 80424 KB Output is correct
2 Correct 248 ms 70248 KB Output is correct
3 Correct 183 ms 65080 KB Output is correct
4 Incorrect 627 ms 72784 KB There must not be two people within the committee such that one person dislikes the other.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 KB Output is correct
2 Correct 2 ms 1116 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Incorrect 3 ms 1116 KB There must not be two people within the committee such that one person dislikes the other.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 239 ms 80468 KB Output is correct
2 Correct 254 ms 79968 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 157 ms 54144 KB Output is correct
5 Correct 198 ms 69680 KB Output is correct
6 Correct 263 ms 68488 KB Output is correct
7 Correct 200 ms 68380 KB Output is correct
8 Execution timed out 3047 ms 66600 KB Time limit exceeded
9 Halted 0 ms 0 KB -