Submission #1014115

# Submission time Handle Problem Language Result Execution time Memory
1014115 2024-07-04T11:09:27 Z 0npata Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
135 ms 24188 KB
#include "supertrees.h"
#include<bits/stdc++.h>

using namespace std;

#define vec vector

int construct(vec<vec<int>> p) {
	int n = p.size();

	vec<vec<int>> edges(n, vec<int>(n, 0));

	vec<int> comp(n, -1);

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

	for(int i = 0; i<n; i++) {
		for(int j = 0; j<n; j++) {
			if(((p[i][j] > 0) != (comp[i] == comp[j])) || p[i][j] == 3) {
				return 0;
			}
		}
	}

	vec<set<int>> comp_cycle(n);

	vec<int> cycle_chains(n, -1);
	for(int i = 0; i<n; i++) {
		for(int j = 0; j<n; j++) {
			if(p[i][j] == 1) {
				cycle_chains[i] = j;
				comp_cycle[comp[i]].insert(j);
				break;
			}
		}
	}

	for(int i = 0; i<n; i++) {
		for(int j = 0; j<n; j++) {
			if(comp[i] != comp[j]) continue;

			if((cycle_chains[i] == cycle_chains[j]) != (p[i][j] == 1)) {
				return 0;
			}
		}
	}

	for(int i = 0; i<n; i++) {
		if(comp[i] != i) continue;
		assert(comp_cycle[i].size() > 0);

		if(comp_cycle[i].size() == 2) return 0;

		if(comp_cycle[i].size() == 1) continue;

		int prev = *comp_cycle[i].end();
		for(int u : comp_cycle[i]) {
			edges[prev][u] = 1;
			edges[u][prev] = 1;
			prev = u;
		}
	}

	for(int i = 0; i<n; i++) {
		for(int j = i-1; j>=0; j--) {
			if(cycle_chains[i] != -1 && cycle_chains[i] == cycle_chains[j]) {
				edges[i][j] = 1;
				edges[j][i] = 1;
				break;
			}
		}
	}

	build(edges);
	return 1;
}
# 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 1372 KB Output is correct
7 Correct 114 ms 24168 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 1372 KB Output is correct
7 Correct 114 ms 24168 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 372 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 1368 KB Output is correct
13 Correct 119 ms 24068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 14164 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6276 KB Output is correct
21 Correct 121 ms 24000 KB Output is correct
22 Correct 122 ms 24072 KB Output is correct
23 Correct 135 ms 24144 KB Output is correct
24 Correct 121 ms 24148 KB Output is correct
25 Correct 58 ms 14072 KB Output is correct
26 Correct 48 ms 14160 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 134 ms 24188 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 Runtime error 0 ms 348 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 0 ms 348 KB Execution killed with signal 11
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 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 1372 KB Output is correct
7 Correct 114 ms 24168 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 372 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 1368 KB Output is correct
13 Correct 119 ms 24068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 14164 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6276 KB Output is correct
21 Correct 121 ms 24000 KB Output is correct
22 Correct 122 ms 24072 KB Output is correct
23 Correct 135 ms 24144 KB Output is correct
24 Correct 121 ms 24148 KB Output is correct
25 Correct 58 ms 14072 KB Output is correct
26 Correct 48 ms 14160 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 134 ms 24188 KB Output is correct
29 Correct 0 ms 344 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 Runtime error 0 ms 348 KB Execution killed with signal 11
34 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 1372 KB Output is correct
7 Correct 114 ms 24168 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 372 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 1368 KB Output is correct
13 Correct 119 ms 24068 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 66 ms 14164 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 29 ms 6276 KB Output is correct
21 Correct 121 ms 24000 KB Output is correct
22 Correct 122 ms 24072 KB Output is correct
23 Correct 135 ms 24144 KB Output is correct
24 Correct 121 ms 24148 KB Output is correct
25 Correct 58 ms 14072 KB Output is correct
26 Correct 48 ms 14160 KB Output is correct
27 Correct 119 ms 24148 KB Output is correct
28 Correct 134 ms 24188 KB Output is correct
29 Correct 0 ms 344 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 Runtime error 0 ms 348 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -