답안 #961853

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961853 2024-04-12T14:55:54 Z NK_ Povjerenstvo (COI22_povjerenstvo) C++17
0 / 100
3000 ms 59324 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> 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;
		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;

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

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



	exit(0-0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 57676 KB Output is correct
2 Correct 240 ms 57260 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 158 ms 42904 KB Output is correct
5 Correct 207 ms 51876 KB Output is correct
6 Correct 231 ms 58184 KB Output is correct
7 Correct 182 ms 43628 KB Output is correct
8 Execution timed out 3064 ms 50296 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 215 ms 57632 KB Output is correct
2 Correct 247 ms 59324 KB Output is correct
3 Correct 160 ms 41672 KB Output is correct
4 Incorrect 637 ms 54744 KB There must not be two people within the committee such that one person dislikes the other.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 864 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 860 KB Output is correct
4 Incorrect 2 ms 980 KB There must not be two people within the committee such that one person dislikes the other.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 57676 KB Output is correct
2 Correct 240 ms 57260 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 158 ms 42904 KB Output is correct
5 Correct 207 ms 51876 KB Output is correct
6 Correct 231 ms 58184 KB Output is correct
7 Correct 182 ms 43628 KB Output is correct
8 Execution timed out 3064 ms 50296 KB Time limit exceeded
9 Halted 0 ms 0 KB -