답안 #958915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958915 2024-04-07T04:56:25 Z ono_de206 Povjerenstvo (COI22_povjerenstvo) C++14
100 / 100
675 ms 110388 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long

typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<int, int> P;

template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
	out << c.first << ' ' << c.second;
	return out;
}

template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
	const int sz = v.size();
	for (int i = 0; i < sz; i++) {
		if (i) out << ' ';
		out << v[i];
	}
	return out;
}

template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
	for (T &x : v) in >> x;
	return in;
}

template<typename T, typename U>
	istream & operator >> (istream &in, pair<T, U> &c) {
	in >> c.first;
	in >> c.second;
	return in;
}

template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}

const int mxn = 5e5 + 10, MXLOG = 22, mod = 1e9 + 7;
const long long inf = 1e18 + 10;
bool did[mxn];
set<int> g[mxn], d[mxn];

void go() {
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].in(y);
		d[y].in(x);
	}
	priority_queue<pair<int, int>> q;
	for(int i = 1; i <= n; i++) {
		q.emplace(-1 * (int)g[i].size(), i);
	}
	vector<int> ans;
	while(q.size()) {
		int sz, x;
		tie(sz, x) = q.top();
		q.pop();
		if(sz != -1 * (int)g[x].size() || did[x] == 1) continue;
		ans.pb(x);
		for(int y : g[x]) {
			did[y] = 1;
		}
		for(int y : d[x]) {
			if(did[y]) continue;
			did[y] = 1;
			for(int z : d[y]) {
				if(did[z]) continue;
				g[z].erase(y);
				q.emplace(-1 * (int)g[z].size(), z);
			}
		}
	}
	cout << ans.size() << endl << ans << endl;
}

signed main() {
	fast;
	int t = 1;
	// cin >> t;
	while(t--) {
		go();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 103616 KB Output is correct
2 Correct 214 ms 105772 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 81 ms 58560 KB Output is correct
5 Correct 129 ms 82200 KB Output is correct
6 Correct 236 ms 105656 KB Output is correct
7 Correct 251 ms 103876 KB Output is correct
8 Correct 317 ms 106672 KB Output is correct
9 Correct 547 ms 107956 KB Output is correct
10 Correct 454 ms 104256 KB Output is correct
11 Correct 520 ms 108844 KB Output is correct
12 Correct 614 ms 104640 KB Output is correct
13 Correct 415 ms 105792 KB Output is correct
14 Correct 382 ms 106056 KB Output is correct
15 Correct 347 ms 106292 KB Output is correct
16 Correct 323 ms 106372 KB Output is correct
17 Correct 131 ms 72396 KB Output is correct
18 Correct 256 ms 98552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 103772 KB Output is correct
2 Correct 246 ms 106676 KB Output is correct
3 Correct 244 ms 100804 KB Output is correct
4 Correct 479 ms 107712 KB Output is correct
5 Correct 650 ms 110120 KB Output is correct
6 Correct 406 ms 107284 KB Output is correct
7 Correct 393 ms 107708 KB Output is correct
8 Correct 352 ms 107336 KB Output is correct
9 Correct 324 ms 106832 KB Output is correct
10 Correct 136 ms 70740 KB Output is correct
11 Correct 61 ms 62152 KB Output is correct
12 Correct 65 ms 62720 KB Output is correct
13 Correct 185 ms 103864 KB Output is correct
14 Correct 225 ms 107592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 48220 KB Output is correct
2 Correct 12 ms 48220 KB Output is correct
3 Correct 12 ms 48312 KB Output is correct
4 Correct 12 ms 48220 KB Output is correct
5 Correct 14 ms 48220 KB Output is correct
6 Correct 13 ms 48220 KB Output is correct
7 Correct 13 ms 48220 KB Output is correct
8 Correct 13 ms 48220 KB Output is correct
9 Correct 11 ms 47960 KB Output is correct
10 Correct 11 ms 47708 KB Output is correct
11 Correct 10 ms 47708 KB Output is correct
12 Correct 12 ms 48284 KB Output is correct
13 Correct 12 ms 48220 KB Output is correct
14 Correct 10 ms 47708 KB Output is correct
15 Correct 13 ms 48220 KB Output is correct
16 Correct 13 ms 48340 KB Output is correct
17 Correct 13 ms 48296 KB Output is correct
18 Correct 11 ms 47964 KB Output is correct
19 Correct 12 ms 48216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 103616 KB Output is correct
2 Correct 214 ms 105772 KB Output is correct
3 Correct 10 ms 47708 KB Output is correct
4 Correct 81 ms 58560 KB Output is correct
5 Correct 129 ms 82200 KB Output is correct
6 Correct 236 ms 105656 KB Output is correct
7 Correct 251 ms 103876 KB Output is correct
8 Correct 317 ms 106672 KB Output is correct
9 Correct 547 ms 107956 KB Output is correct
10 Correct 454 ms 104256 KB Output is correct
11 Correct 520 ms 108844 KB Output is correct
12 Correct 614 ms 104640 KB Output is correct
13 Correct 415 ms 105792 KB Output is correct
14 Correct 382 ms 106056 KB Output is correct
15 Correct 347 ms 106292 KB Output is correct
16 Correct 323 ms 106372 KB Output is correct
17 Correct 131 ms 72396 KB Output is correct
18 Correct 256 ms 98552 KB Output is correct
19 Correct 198 ms 103772 KB Output is correct
20 Correct 246 ms 106676 KB Output is correct
21 Correct 244 ms 100804 KB Output is correct
22 Correct 479 ms 107712 KB Output is correct
23 Correct 650 ms 110120 KB Output is correct
24 Correct 406 ms 107284 KB Output is correct
25 Correct 393 ms 107708 KB Output is correct
26 Correct 352 ms 107336 KB Output is correct
27 Correct 324 ms 106832 KB Output is correct
28 Correct 136 ms 70740 KB Output is correct
29 Correct 61 ms 62152 KB Output is correct
30 Correct 65 ms 62720 KB Output is correct
31 Correct 185 ms 103864 KB Output is correct
32 Correct 225 ms 107592 KB Output is correct
33 Correct 13 ms 48220 KB Output is correct
34 Correct 12 ms 48220 KB Output is correct
35 Correct 12 ms 48312 KB Output is correct
36 Correct 12 ms 48220 KB Output is correct
37 Correct 14 ms 48220 KB Output is correct
38 Correct 13 ms 48220 KB Output is correct
39 Correct 13 ms 48220 KB Output is correct
40 Correct 13 ms 48220 KB Output is correct
41 Correct 11 ms 47960 KB Output is correct
42 Correct 11 ms 47708 KB Output is correct
43 Correct 10 ms 47708 KB Output is correct
44 Correct 12 ms 48284 KB Output is correct
45 Correct 12 ms 48220 KB Output is correct
46 Correct 10 ms 47708 KB Output is correct
47 Correct 13 ms 48220 KB Output is correct
48 Correct 13 ms 48340 KB Output is correct
49 Correct 13 ms 48296 KB Output is correct
50 Correct 11 ms 47964 KB Output is correct
51 Correct 12 ms 48216 KB Output is correct
52 Correct 229 ms 106160 KB Output is correct
53 Correct 261 ms 106760 KB Output is correct
54 Correct 238 ms 101792 KB Output is correct
55 Correct 517 ms 107620 KB Output is correct
56 Correct 675 ms 110388 KB Output is correct
57 Correct 459 ms 107068 KB Output is correct
58 Correct 390 ms 107424 KB Output is correct
59 Correct 350 ms 107196 KB Output is correct
60 Correct 146 ms 72944 KB Output is correct
61 Correct 63 ms 62156 KB Output is correct
62 Correct 67 ms 62676 KB Output is correct
63 Correct 220 ms 104120 KB Output is correct
64 Correct 202 ms 105564 KB Output is correct
65 Correct 80 ms 65012 KB Output is correct
66 Correct 617 ms 106700 KB Output is correct
67 Correct 422 ms 108208 KB Output is correct
68 Correct 411 ms 106428 KB Output is correct
69 Correct 165 ms 71892 KB Output is correct
70 Correct 265 ms 105152 KB Output is correct