Submission #1085296

# Submission time Handle Problem Language Result Execution time Memory
1085296 2024-09-07T21:52:06 Z an22inkle Connecting Supertrees (IOI20_supertrees) C++17
46 / 100
143 ms 24400 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using pair = std::array<int, 2>;
using ll = long long;

void adjlist(std::vector<std::vector<int>> p) {
	int n = p.size();
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[i][j]) std::cout << i << ' ' << j << '\n';
		}
	}
	std::cout << '\n';
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> ans(n, std::vector<int>(n)), groups;
	std::vector<int> part(n, -1);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j || p[i][j] == 0) continue;
	
			if (part[i] > -1 && part[j] > -1) {
				if (part[i] != part[j]) return 0;
				continue;
			}

			if (part[i] > -1) groups[part[i]].push_back(j), part[j] = part[i];
			else if (part[j] > -1) groups[part[j]].push_back(i), part[i] = part[j];
			else {
				groups.push_back({i, j});
				// groups.back().push_back(i);
				// groups.back().push_back(j);
				part[i] = part[j] = groups.size() - 1;
			}
		}
	}

	for (auto group : groups) {
		int type = 0;
		int m = group.size();
		for (int i = 0; i < m; i++) {
			for (int j = i+1; j < m; j++) {
				type = std::max(type, p[group[i]][group[j]]);
			}
		}

		for (int i = 0; i < m && type == 1; i++) {
			if (i != m - 1) ans[group[i]][group[(i+1)]] = ans[group[(i + 1)]][group[i]] = 1;	
		}

		if (type == 1) continue;

		std::vector<int> o = {group[0]}, vis(m); vis[0] = 1;
		// Add elements that require two paths to all present in o;
		for (int i = 1; i < m; i++) {
			int ok = 1;
			for (auto c : o) {
				if (p[group[i]][c] != 2) ok = 0; 
			}
			if (ok) o.push_back(group[i]), vis[i] = 1;
		}

		for (int i = 1; i <= o.size(); i++) {
			ans[o[i-1]][o[i%o.size()]] = ans[o[i%o.size()]][o[i-1]] = 1;
		}

		for (int i = 0; i < m; i++) {
			if (vis[i]) continue;
			for (auto c : o) {
				if (p[c][group[i]] == 1) {
					ans[c][group[i]] = ans[group[i]][c] = 1;
				}
			}
		}
	}

	// adjlist(ans);
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:66:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |   for (int i = 1; i <= o.size(); i++) {
      |                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 5 ms 1364 KB Output is correct
7 Correct 117 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 5 ms 1364 KB Output is correct
7 Correct 117 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 123 ms 24196 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 352 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 29 ms 6356 KB Output is correct
5 Correct 126 ms 23928 KB Output is correct
6 Correct 115 ms 24144 KB Output is correct
7 Correct 124 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 29 ms 6268 KB Output is correct
10 Correct 115 ms 24144 KB Output is correct
11 Correct 122 ms 24400 KB Output is correct
12 Correct 135 ms 23948 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 29 ms 6416 KB Output is correct
17 Correct 114 ms 24144 KB Output is correct
18 Correct 117 ms 24148 KB Output is correct
19 Correct 113 ms 23944 KB Output is correct
20 Correct 143 ms 24148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 5 ms 1364 KB Output is correct
7 Correct 117 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 123 ms 24196 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 5 ms 1364 KB Output is correct
7 Correct 117 ms 24144 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 123 ms 24196 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -