Submission #823614

# Submission time Handle Problem Language Result Execution time Memory
823614 2023-08-12T21:51:39 Z GusterGoose27 Connecting Supertrees (IOI20_supertrees) C++17
56 / 100
184 ms 24088 KB
#include "supertrees.h"
#include <bits/stdc++.h>

const int MAXN = 1e3+5;

using namespace std;
int n;
int uf[MAXN];

int find(int i) {
	return uf[i] == i ? i : uf[i] = find(uf[i]);
}

void merge(int a, int b) {
	a = find(a);
	b = find(b);
	assert(a != b);
	uf[a] = b;
}

bool vis[MAXN];

int construct(vector<vector<int>> p) {
	n = p.size();
	iota(uf, uf+n, 0);
	vector<vector<int>> answer(n, vector<int>(n, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] == 3) return 0;
			if (find(i) != find(j) && p[i][j] == 1) {
				answer[i][j] = answer[j][i] = 1;
				merge(i, j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] == 1 && find(i) != find(j)) return 0;
			if (p[i][j] != 1 && find(i) == find(j)) return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		vector<int> vals;
		int cur = find(i);
		if (vis[cur]) continue;
		do {
			if (vals.size()) merge(vals.back(), cur);
			vals.push_back(cur);
			vis[cur] = 1;
			bool f = 0;
			for (int j = 0; j < n; j++) {
				if (uf[j] != j || vis[j] || j == find(i)) continue;
				if (p[cur][j] == 2) {
					f = 1;
					cur = j;
					break;
				}
			}
			if (!f) cur = find(i);
		} while (cur != find(i));
		if (vals.size() > 1){
			for (int j = 0; j < vals.size(); j++) {
				answer[vals[j]][vals[(j+1)%vals.size()]] = 
				answer[vals[(j+1)%vals.size()]][vals[j]] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] >= 1 && find(i) != find(j)) return 0;
			if (p[i][j] == 0 && find(i) == find(j)) return 0;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:62:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for (int j = 0; j < vals.size(); j++) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1216 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1216 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 69 ms 14068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6136 KB Output is correct
21 Correct 183 ms 23892 KB Output is correct
22 Correct 159 ms 23928 KB Output is correct
23 Correct 184 ms 23900 KB Output is correct
24 Correct 159 ms 23976 KB Output is correct
25 Correct 72 ms 14068 KB Output is correct
26 Correct 67 ms 14084 KB Output is correct
27 Correct 171 ms 23932 KB Output is correct
28 Correct 157 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 41 ms 6232 KB Output is correct
5 Correct 165 ms 23924 KB Output is correct
6 Correct 159 ms 23944 KB Output is correct
7 Correct 181 ms 24012 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 40 ms 6264 KB Output is correct
10 Correct 161 ms 23928 KB Output is correct
11 Correct 160 ms 23944 KB Output is correct
12 Correct 172 ms 24088 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 40 ms 6260 KB Output is correct
17 Correct 159 ms 24056 KB Output is correct
18 Correct 161 ms 23948 KB Output is correct
19 Correct 160 ms 23932 KB Output is correct
20 Correct 170 ms 23960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1216 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 69 ms 14068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6136 KB Output is correct
21 Correct 183 ms 23892 KB Output is correct
22 Correct 159 ms 23928 KB Output is correct
23 Correct 184 ms 23900 KB Output is correct
24 Correct 159 ms 23976 KB Output is correct
25 Correct 72 ms 14068 KB Output is correct
26 Correct 67 ms 14084 KB Output is correct
27 Correct 171 ms 23932 KB Output is correct
28 Correct 157 ms 23900 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 9 ms 1216 KB Output is correct
7 Correct 165 ms 23924 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 7 ms 1212 KB Output is correct
13 Correct 158 ms 23948 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 69 ms 14068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 40 ms 6136 KB Output is correct
21 Correct 183 ms 23892 KB Output is correct
22 Correct 159 ms 23928 KB Output is correct
23 Correct 184 ms 23900 KB Output is correct
24 Correct 159 ms 23976 KB Output is correct
25 Correct 72 ms 14068 KB Output is correct
26 Correct 67 ms 14084 KB Output is correct
27 Correct 171 ms 23932 KB Output is correct
28 Correct 157 ms 23900 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 296 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -