답안 #35554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
35554 2017-11-24T16:11:28 Z szawinis Conspiracy (POI11_kon) C++14
80 / 100
2703 ms 5280 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);

	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;
		// cout << deg[ord[i]] << ' ' << ord[i] << ' ' << valid[ord[i]] << endl;
	}
	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]];
		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;//, cout << (g[ord[i]] | fin).to_string() << endl;
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5280 KB Output is correct
2 Correct 0 ms 5280 KB Output is correct
3 Correct 0 ms 5280 KB Output is correct
4 Incorrect 0 ms 5280 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5280 KB Output is correct
2 Correct 0 ms 5280 KB Output is correct
3 Correct 0 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5280 KB Output is correct
2 Correct 0 ms 5280 KB Output is correct
3 Correct 0 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5280 KB Output is correct
2 Correct 3 ms 5280 KB Output is correct
3 Correct 0 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5280 KB Output is correct
2 Correct 3 ms 5280 KB Output is correct
3 Correct 3 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5280 KB Output is correct
2 Correct 66 ms 5280 KB Output is correct
3 Correct 279 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5280 KB Output is correct
2 Correct 76 ms 5280 KB Output is correct
3 Correct 359 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 5280 KB Output is correct
2 Correct 203 ms 5280 KB Output is correct
3 Correct 629 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 5280 KB Output is correct
2 Correct 416 ms 5280 KB Output is correct
3 Correct 1566 ms 5280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1116 ms 5280 KB Output is correct
2 Correct 683 ms 5280 KB Output is correct
3 Correct 2446 ms 5280 KB Output is correct
4 Correct 2703 ms 5280 KB Output is correct
5 Incorrect 33 ms 5280 KB Output isn't correct