답안 #68141

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68141 2018-08-16T06:46:35 Z MrTEK Conspiracy (POI11_kon) C++11
100 / 100
2623 ms 88468 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3+1;
 
int n, dsu[N];
bitset<N> g[N], valid;
 
int root(int v) { return (dsu[v] < 0 ? v : dsu[v] = root(dsu[v])); }
void merge(int u, int v) {
	if((u = root(u)) == (v = root(v))) return;
	dsu[u] += dsu[v];
	dsu[v] = u;
}
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	fill(dsu, dsu+n, -1);
	vector<int> deg(n+1), ord(n+1);
	deg[n] = -1;
 
	for(int i = 0; i < n; i++) {
		cin >> deg[i];
		for(int j = 0, v; j < deg[i]; j++) {
			cin >> v; --v;
			g[i].set(v);
		}
	}
 
	iota(ord.begin(), ord.end(), 0);
	sort(ord.begin(), ord.end(), [&] (int i, int j) { return deg[i] > deg[j]; });
	valid[n] = true;
	for(int i = n-1; i >= 0; i--) {
		for(int j = i+1; j < n; j++) if(g[ord[i]][ord[j]]) merge(ord[i], ord[j]);
		valid[ord[i]] = dsu[root(ord[i])] == -1;
	}
 
	int lim = -1;
	bool run = true;
	bitset<N> fin;
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < i; j++) run &= g[ord[i]][ord[j]] || dsu[root(ord[i])] == -1 || dsu[root(ord[j])] == -1;
		if(!run) break;
		if(i == n-1 || (valid[ord[i+1]] && deg[ord[i+1]] != deg[ord[i]])) {
			lim = i;
			for(int k = 0; k <= i; k++) fin.set(ord[k]);
			break;
		} 
	}
 
	if(lim == -1) cout << 0, exit(0);
	int ans = lim < n-1;
	for(int i = 0; i <= lim; i++) ans += (g[ord[i]] | fin) == fin;
	if(lim < n-2) for(int i = lim+1; i < n; i++) ans += g[ord[i]] == fin;
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 532 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 644 KB Output is correct
2 Correct 3 ms 664 KB Output is correct
3 Correct 3 ms 676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 676 KB Output is correct
2 Correct 5 ms 800 KB Output is correct
3 Correct 4 ms 880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1056 KB Output is correct
2 Correct 8 ms 1100 KB Output is correct
3 Correct 8 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2092 KB Output is correct
2 Correct 74 ms 4868 KB Output is correct
3 Correct 346 ms 18128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 18236 KB Output is correct
2 Correct 134 ms 22396 KB Output is correct
3 Correct 506 ms 40244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 43032 KB Output is correct
2 Correct 352 ms 51856 KB Output is correct
3 Correct 669 ms 56116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 56788 KB Output is correct
2 Correct 611 ms 56788 KB Output is correct
3 Correct 1785 ms 56932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1116 ms 57360 KB Output is correct
2 Correct 950 ms 88468 KB Output is correct
3 Correct 2343 ms 88468 KB Output is correct
4 Correct 2623 ms 88468 KB Output is correct
5 Correct 88 ms 88468 KB Output is correct