Submission #1085272

# Submission time Handle Problem Language Result Execution time Memory
1085272 2024-09-07T19:47:41 Z an22inkle Connecting Supertrees (IOI20_supertrees) C++17
11 / 100
115 ms 24144 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using pair = std::array<int, 2>;
using ll = long long;

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]] = 2;
		}

		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;
				}
			}
		}
	}

	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 115 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 115 ms 24144 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 115 ms 23892 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 1 ms 348 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 348 KB Output is correct
2 Incorrect 0 ms 348 KB Integer element b_i_j[2] equals to 2, violates the range [0, 1]
3 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 115 ms 24144 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 115 ms 23892 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 115 ms 24144 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 5 ms 1372 KB Output is correct
13 Correct 115 ms 23892 KB Output is correct
14 Incorrect 0 ms 348 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -