답안 #854517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854517 2023-09-27T19:41:21 Z IBory Conspiracy (POI11_kon) C++17
80 / 100
1244 ms 25184 KB
#include <bits/stdc++.h>
using namespace std;

const int MAX = 5005;
bool G[MAX][MAX];
int N, V[MAX], out[MAX], cnt;

void Fail() {
	cout << 0;
	exit(0);
}

void DFS(int cur) {
	cnt++;
	for (int next = 1; next <= N; ++next) {
		if (V[next] || !G[cur][next]) continue;
		V[next] = 1;
		DFS(next);
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int ans = 0, E = 0;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> out[i];
		E += out[i];
		for (int j = 0; j < out[i]; ++j) {
			int n;
			cin >> n;
			G[i][n] = 1;
		}
	}

	int one = 0, comp = 0;
	vector<int> S;
	for (int i = 1; i <= N; ++i) {
		if (V[i]) continue;
		cnt = 0; V[i] = 1; DFS(i);
		if (cnt == 1) {
			one++;
			S.push_back(i);
		}
		else comp++;
	}

	if (comp > 1) Fail();

	int cn = N - one;
	do {
		if (E == cn * (cn - 1)) break;
		int cand = 0, ec = 1e9;
		for (int i = 1; i <= N; ++i) {
			if (out[i] > 0 && ec > out[i]) {
				ec = out[i];
				cand = i;
			}
		}

		for (int i = 1; i <= N; ++i) {
			if (!G[cand][i]) continue;
			if (!G[i][cand]) Fail();
			out[i]--;
			G[cand][i] = 0;
		}

		out[cand] = 0;
		S.push_back(cand);
		E -= ec * 2;
	} while (--cn);

	// Init
	int temp = 1;
	for (int n1 : S) for (int n2 : S) if (G[n1][n2]) temp = 0;
	ans += temp;

	// -1
	for (int i = 1; i <= N; ++i) {
		if (!out[i]) continue;
		int ok = 1;
		for (int n : S) {
			if (G[i][n]) {
				ok = 0;
				break;
			}
		}
		if (ok) ans++;
	}

	// Replace
	for (int n1 : S) {
		int go = 0, r = 0;
		for (int i = 1; i <= N; ++i) {
			if (G[i][n1]) go++;
			else if (out[i]) r = i;
		}
		if (go != cn - 1) continue;
		int ok = 1;
		for (int n2 : S) {
			if (n1 == n2) continue;
			if (G[r][n2]) {
				ok = 0;
				break;
			}
		}
		if (ok) ans++;
	}

	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 3 ms 2640 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8796 KB Output is correct
2 Correct 36 ms 8772 KB Output is correct
3 Correct 154 ms 10848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8796 KB Output is correct
2 Correct 53 ms 10872 KB Output is correct
3 Correct 200 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 12892 KB Output is correct
2 Correct 114 ms 14944 KB Output is correct
3 Correct 328 ms 15208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 21072 KB Output is correct
2 Correct 271 ms 21104 KB Output is correct
3 Correct 749 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 24948 KB Output is correct
2 Correct 461 ms 24916 KB Output is correct
3 Correct 1172 ms 25168 KB Output is correct
4 Incorrect 1244 ms 25184 KB Output isn't correct
5 Halted 0 ms 0 KB -