Submission #1014116

# Submission time Handle Problem Language Result Execution time Memory
1014116 2024-07-04T11:13:14 Z 0npata Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
148 ms 23540 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() == 0) return 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 1 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 424 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 112 ms 23380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 424 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 112 ms 23380 KB Output is correct
8 Correct 0 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 1376 KB Output is correct
13 Correct 114 ms 23540 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 860 KB Output is correct
17 Correct 55 ms 13532 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 28 ms 6256 KB Output is correct
21 Correct 142 ms 23376 KB Output is correct
22 Correct 113 ms 23376 KB Output is correct
23 Correct 119 ms 23304 KB Output is correct
24 Correct 107 ms 23376 KB Output is correct
25 Correct 51 ms 13392 KB Output is correct
26 Correct 50 ms 13300 KB Output is correct
27 Correct 117 ms 23364 KB Output is correct
28 Correct 148 ms 23376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 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 0 ms 344 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 1 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 424 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 112 ms 23380 KB Output is correct
8 Correct 0 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 1376 KB Output is correct
13 Correct 114 ms 23540 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 860 KB Output is correct
17 Correct 55 ms 13532 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 28 ms 6256 KB Output is correct
21 Correct 142 ms 23376 KB Output is correct
22 Correct 113 ms 23376 KB Output is correct
23 Correct 119 ms 23304 KB Output is correct
24 Correct 107 ms 23376 KB Output is correct
25 Correct 51 ms 13392 KB Output is correct
26 Correct 50 ms 13300 KB Output is correct
27 Correct 117 ms 23364 KB Output is correct
28 Correct 148 ms 23376 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 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 1 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 424 KB Output is correct
6 Correct 5 ms 1372 KB Output is correct
7 Correct 112 ms 23380 KB Output is correct
8 Correct 0 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 1376 KB Output is correct
13 Correct 114 ms 23540 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 860 KB Output is correct
17 Correct 55 ms 13532 KB Output is correct
18 Correct 0 ms 432 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 28 ms 6256 KB Output is correct
21 Correct 142 ms 23376 KB Output is correct
22 Correct 113 ms 23376 KB Output is correct
23 Correct 119 ms 23304 KB Output is correct
24 Correct 107 ms 23376 KB Output is correct
25 Correct 51 ms 13392 KB Output is correct
26 Correct 50 ms 13300 KB Output is correct
27 Correct 117 ms 23364 KB Output is correct
28 Correct 148 ms 23376 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 344 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 -