Submission #1084746

# Submission time Handle Problem Language Result Execution time Memory
1084746 2024-09-06T22:15:35 Z an22inkle Connecting Supertrees (IOI20_supertrees) C++17
40 / 100
150 ms 24148 KB
#include<bits/stdc++.h>
#include "supertrees.h"
using pair = std::array<int, 2>;
using ll = long long;

void stress(std::vector<std::vector<int>> p, std::vector<std::vector<int>> ans) {
	int n = p.size();
	std::vector<std::vector<int>> hits(n, std::vector<int>(n));
	auto adj = hits;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
				if (i == j or ans[i][j] == 0) continue;
				adj[i].push_back(j);
				adj[j].push_back(i);
		}
	}

	std::function<int(int, int, int)> dfs = [&](int u, int parent, int target) {
		if (target == u) return 1;
		int res = 0;
		for (auto v : adj[u]) {
			if (parent == v) continue;
			res += dfs(v, u, target);
		}
		return res;
	};

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) hits[i][i] = 1;
			else hits[i][j] = dfs(i, -1, j);

			if (hits[i][j] != p[i][j]) {
				std::cout << "mismatch\n" << i << ' ' << j << " expected " << p[i][j] << " got " << hits[i][j] << '\n';;
			}
		}
	}

	std::cout << "stress test ok\n";
}

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

	int max = 0;
	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;
			}

			max = std::max(p[i][j], max);
			if (part[i] > -1) lines[part[i]].push_back(j), part[j] = part[i];
			else if (part[j] > -1) lines[part[j]].push_back(i), part[i] = part[j];
			else {
				lines.push_back({});
				lines.back().push_back(i);
				lines.back().push_back(j);
				part[i] = part[j] = lines.size() - 1;
			}
		}
	}

	for (auto line : lines) {
		if (max == 2 && line.size() == 2) return 0;
		for (int i = 0; i < line.size(); i++) {
			for (int j = i+1; j < line.size(); j++) {
				if (p[line[i]][line[j]] == 0) return 0;
			}
			// std::cout << line[i] << ' ';
			if (max == 2) {
				ans[line[i]][line[(i+1)%line.size()]] = ans[line[(i + 1)%line.size()]][line[i]] = 1;	
			} else {
				if (i != line.size() - 1) ans[line[i]][line[(i+1)]] = ans[line[(i + 1)]][line[i]] = 1;	
			}
			
		} // std::cout << '\n';
	}

	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for (int i = 0; i < line.size(); i++) {
      |                   ~~^~~~~~~~~~~~~
supertrees.cpp:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (int j = i+1; j < line.size(); j++) {
      |                      ~~^~~~~~~~~~~~~
supertrees.cpp:80:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     if (i != line.size() - 1) ans[line[i]][line[(i+1)]] = ans[line[(i + 1)]][line[i]] = 1;
      |         ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 9 ms 1372 KB Output is correct
7 Correct 122 ms 23924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 9 ms 1372 KB Output is correct
7 Correct 122 ms 23924 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 114 ms 24068 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 74 ms 14076 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 30 ms 6216 KB Output is correct
21 Correct 127 ms 24148 KB Output is correct
22 Correct 139 ms 23932 KB Output is correct
23 Correct 124 ms 24144 KB Output is correct
24 Correct 116 ms 23892 KB Output is correct
25 Correct 51 ms 14416 KB Output is correct
26 Correct 50 ms 14164 KB Output is correct
27 Correct 125 ms 24072 KB Output is correct
28 Correct 116 ms 23924 KB Output is correct
# 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 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 5 ms 1116 KB Output is correct
9 Correct 123 ms 22036 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 5 ms 1116 KB Output is correct
13 Correct 150 ms 22040 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 61 ms 12040 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 28 ms 5892 KB Output is correct
22 Correct 116 ms 22092 KB Output is correct
23 Correct 133 ms 22032 KB Output is correct
24 Correct 123 ms 22096 KB Output is correct
25 Correct 50 ms 12112 KB Output is correct
26 Correct 55 ms 12116 KB Output is correct
27 Correct 124 ms 22104 KB Output is correct
28 Correct 120 ms 22096 KB Output is correct
29 Correct 53 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 29 ms 6220 KB Output is correct
5 Correct 145 ms 24148 KB Output is correct
6 Correct 137 ms 24148 KB Output is correct
7 Correct 130 ms 24064 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 29 ms 6236 KB Output is correct
10 Correct 126 ms 24144 KB Output is correct
11 Correct 117 ms 24148 KB Output is correct
12 Correct 136 ms 24144 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Incorrect 0 ms 348 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 9 ms 1372 KB Output is correct
7 Correct 122 ms 23924 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 114 ms 24068 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 74 ms 14076 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 30 ms 6216 KB Output is correct
21 Correct 127 ms 24148 KB Output is correct
22 Correct 139 ms 23932 KB Output is correct
23 Correct 124 ms 24144 KB Output is correct
24 Correct 116 ms 23892 KB Output is correct
25 Correct 51 ms 14416 KB Output is correct
26 Correct 50 ms 14164 KB Output is correct
27 Correct 125 ms 24072 KB Output is correct
28 Correct 116 ms 23924 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 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 123 ms 22036 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 150 ms 22040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 61 ms 12040 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5892 KB Output is correct
50 Correct 116 ms 22092 KB Output is correct
51 Correct 133 ms 22032 KB Output is correct
52 Correct 123 ms 22096 KB Output is correct
53 Correct 50 ms 12112 KB Output is correct
54 Correct 55 ms 12116 KB Output is correct
55 Correct 124 ms 22104 KB Output is correct
56 Correct 120 ms 22096 KB Output is correct
57 Correct 53 ms 12116 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 3 ms 856 KB Output is correct
61 Correct 65 ms 14212 KB Output is correct
62 Correct 0 ms 344 KB Output is correct
63 Incorrect 0 ms 348 KB Too many ways to get from 0 to 9, should be 1 found no less than 2
64 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 9 ms 1372 KB Output is correct
7 Correct 122 ms 23924 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 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 114 ms 24068 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 3 ms 932 KB Output is correct
17 Correct 74 ms 14076 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 30 ms 6216 KB Output is correct
21 Correct 127 ms 24148 KB Output is correct
22 Correct 139 ms 23932 KB Output is correct
23 Correct 124 ms 24144 KB Output is correct
24 Correct 116 ms 23892 KB Output is correct
25 Correct 51 ms 14416 KB Output is correct
26 Correct 50 ms 14164 KB Output is correct
27 Correct 125 ms 24072 KB Output is correct
28 Correct 116 ms 23924 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 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 5 ms 1116 KB Output is correct
37 Correct 123 ms 22036 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 0 ms 344 KB Output is correct
40 Correct 5 ms 1116 KB Output is correct
41 Correct 150 ms 22040 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 61 ms 12040 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 28 ms 5892 KB Output is correct
50 Correct 116 ms 22092 KB Output is correct
51 Correct 133 ms 22032 KB Output is correct
52 Correct 123 ms 22096 KB Output is correct
53 Correct 50 ms 12112 KB Output is correct
54 Correct 55 ms 12116 KB Output is correct
55 Correct 124 ms 22104 KB Output is correct
56 Correct 120 ms 22096 KB Output is correct
57 Correct 53 ms 12116 KB Output is correct
58 Correct 0 ms 344 KB Output is correct
59 Correct 0 ms 344 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 29 ms 6220 KB Output is correct
62 Correct 145 ms 24148 KB Output is correct
63 Correct 137 ms 24148 KB Output is correct
64 Correct 130 ms 24064 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 29 ms 6236 KB Output is correct
67 Correct 126 ms 24144 KB Output is correct
68 Correct 117 ms 24148 KB Output is correct
69 Correct 136 ms 24144 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Incorrect 0 ms 348 KB Too many ways to get from 4 to 8, should be 1 found no less than 2
72 Halted 0 ms 0 KB -