답안 #854501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854501 2023-09-27T18:56:10 Z IBory Conspiracy (POI11_kon) C++17
0 / 100
1192 ms 131072 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]) continue;
		V[next] = 1;
		DFS(next);
	}
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int ans = 1, 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> isolated;
	for (int i = 1; i <= N; ++i) {
		if (V[i]) continue;
		cnt = 0; V[i] = 1; DFS(i);
		if (cnt == 1) {
			one++;
			isolated.push_back(i);
		}
		else comp++;
	}

	if (comp > 1) Fail();

	int curNode = N - one;
	do {
		if (E == curNode * (curNode - 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;
		isolated.push_back(cand);
		E -= ec * 2;
	} while (--curNode);

	for (int i = 1; i <= N; ++i) {
		if (!out[i]) continue;
		int ok = 1;
		for (int n : isolated) {
			if (G[i][n]) {
				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 1 ms 344 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Incorrect 1 ms 2532 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Incorrect 1 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 4 ms 2648 KB Output is correct
3 Incorrect 2 ms 2652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9052 KB Output is correct
2 Incorrect 36 ms 11440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9052 KB Output is correct
2 Incorrect 52 ms 14684 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 15588 KB Output is correct
2 Incorrect 112 ms 23768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 25680 KB Output is correct
2 Incorrect 286 ms 41572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 550 ms 72596 KB Output is correct
2 Correct 408 ms 55600 KB Output is correct
3 Incorrect 1192 ms 131072 KB Output isn't correct
4 Halted 0 ms 0 KB -