답안 #1005207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005207 2024-06-22T08:52:01 Z thinknoexit 슈퍼트리 잇기 (IOI20_supertrees) C++17
56 / 100
113 ms 24224 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
int p[N], p2[N];
int fr(int i) {
	return p[i] == i ? i : p[i] = fr(p[i]);
}
int fr2(int i) {
	return p2[i] == i ? i : p2[i] = fr2(p2[i]);
}
int construct(vector<vector<int>> B) {
	int n = B.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));
	// Calculate for p[i][j] = 1
	iota(p, p + n, 0);
	for (int i = 0;i < n;i++) {
		for (int j = i + 1;j < n;j++) {
			if (B[i][j] == 1) {
				p[fr(i)] = fr(j);
			}
		}
	}
	vector<vector<int>> g(n);
	for (int i = 0;i < n;i++) {
		g[fr(i)].push_back(i);
	}
	vector<int> node;
	for (int G = 0;G < n;G++) {
		if (g[G].empty()) continue;
		node.push_back(G);
		auto& v = g[G];
		int m = v.size();
		int cnt = 0;
		for (int i = 0;i < m;i++) {
			for (int j = i + 1;j < m;j++) {
				if (B[v[i]][v[j]] != 1) return 0;
			}
		}
		for (int i = 1;i < m;i++) {
			ans[v[0]][v[i]] = ans[v[i]][v[0]] = 1;
		}
	}
	iota(p2, p2 + n, 0);
	int k = node.size();
	for (int i = 0;i < k;i++) {
		for (int j = i + 1;j < k;j++) {
			if (B[node[i]][node[j]] == 2) {
				p2[fr2(node[i])] = fr2(node[j]);
			}
		}
	}
	vector<vector<int>> g2(n);
	for (int i = 0;i < k;i++) {
		g2[fr2(node[i])].push_back(node[i]);
	}
	for (int G = 0;G < n;G++) {
		if (g2[G].empty() || (int)g2[G].size() == 1) continue;
		//if ((int)g2[G].size() == 2) return 0;

		auto& v = g2[G];
		int m = v.size();
		int cnt = 0;
		for (int i = 0;i < m;i++) {
			for (int j = i + 1;j < m;j++) {
				if (B[v[i]][v[j]] != 2) return 0;
			}
		}
		for (int i = 0;i < m;i++) {
			ans[v[(i + 1) % m]][v[i]] = ans[v[i]][v[(i + 1) % m]] = 1;
		}
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:35:7: warning: unused variable 'cnt' [-Wunused-variable]
   35 |   int cnt = 0;
      |       ^~~
supertrees.cpp:64:7: warning: unused variable 'cnt' [-Wunused-variable]
   64 |   int cnt = 0;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 91 ms 22028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 91 ms 22028 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 110 ms 22296 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 56 ms 12060 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5752 KB Output is correct
21 Correct 104 ms 22192 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 113 ms 22100 KB Output is correct
24 Correct 99 ms 22104 KB Output is correct
25 Correct 47 ms 12112 KB Output is correct
26 Correct 41 ms 12112 KB Output is correct
27 Correct 102 ms 22028 KB Output is correct
28 Correct 103 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 25 ms 5720 KB Output is correct
5 Correct 97 ms 22180 KB Output is correct
6 Correct 100 ms 22100 KB Output is correct
7 Correct 113 ms 22096 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 27 ms 5844 KB Output is correct
10 Correct 112 ms 22284 KB Output is correct
11 Correct 106 ms 22096 KB Output is correct
12 Correct 108 ms 22284 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 26 ms 6232 KB Output is correct
17 Correct 104 ms 24076 KB Output is correct
18 Correct 109 ms 24224 KB Output is correct
19 Correct 99 ms 24144 KB Output is correct
20 Correct 106 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 91 ms 22028 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 110 ms 22296 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 56 ms 12060 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5752 KB Output is correct
21 Correct 104 ms 22192 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 113 ms 22100 KB Output is correct
24 Correct 99 ms 22104 KB Output is correct
25 Correct 47 ms 12112 KB Output is correct
26 Correct 41 ms 12112 KB Output is correct
27 Correct 102 ms 22028 KB Output is correct
28 Correct 103 ms 22100 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 4 ms 1284 KB Output is correct
7 Correct 91 ms 22028 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 110 ms 22296 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 860 KB Output is correct
17 Correct 56 ms 12060 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 28 ms 5752 KB Output is correct
21 Correct 104 ms 22192 KB Output is correct
22 Correct 112 ms 22100 KB Output is correct
23 Correct 113 ms 22100 KB Output is correct
24 Correct 99 ms 22104 KB Output is correct
25 Correct 47 ms 12112 KB Output is correct
26 Correct 41 ms 12112 KB Output is correct
27 Correct 102 ms 22028 KB Output is correct
28 Correct 103 ms 22100 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -