Submission #839160

# Submission time Handle Problem Language Result Execution time Memory
839160 2023-08-28T22:11:32 Z tranxuanbach Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
182 ms 28120 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

#define isz(a) ((signed)a.size())

const int N = 1e3 + 5;

int n;
vector <vector <int>> cnt_path;

vector <vector <int>> adj;

bool check_clique(const vector <int>& a, int l, int r){
	for (auto u: a){
		for (auto v: a){
			if (u >= v){
				continue;
			}
			if (not (l <= cnt_path[u][v] and cnt_path[u][v] <= r)){
				return false;
			}
		}
	}
	return true;
}

vector <bool> vis;

void dfs(int u, int l, int r, vector <int>& a){
	vis[u] = true;
	a.emplace_back(u);
	for (int v = 0; v < n; v++){
		if (not vis[v] and l <= cnt_path[u][v] and cnt_path[u][v] <= r){
			dfs(v, l, r, a);
		}
	}
}

vector <bool> is_end;

int construct(vector <vector <int>> _p){
	n = isz(_p);
	cnt_path = _p;

	adj.assign(n, vector <int>(n, 0));
	vis.assign(n, false);
	is_end.assign(n, false);

	for (int u = 0; u < n; u++){
		if (vis[u]){
			continue;
		}
		vector <int> a;
		dfs(u, 1, 1, a);
		if (not check_clique(a, 1, 1)){
			return 0;
		}
		for (int i = 0; i + 1 < isz(a); i++){
			int u = a[i], v = a[i + 1];
			adj[u][v] = adj[v][u] = 1;
		}
		is_end[a.back()] = true;
	}

	vis.assign(n, false);
	for (int u = 0; u < n; u++){
		if (vis[u]){
			continue;
		}
		vector <int> a;
		dfs(u, 1, 2, a);
		if (not check_clique(a, 1, 2)){
			return 0;
		}
		vector <int> b;
		for (auto u: a){
			if (is_end[u]){
				b.emplace_back(u);
			}
		}
		if (isz(b) == 1){
			continue;
		}
		if (isz(b) == 2){
			return 0;
		}
		for (int i = 0; i < isz(b); i++){
			int u = b[i], v = b[(i + 1) % isz(b)];
			adj[u][v] = adj[v][u] = 1;
		}
	}

	for (int u = 0; u < n; u++){
		for (int v = 0; v < n; v++){
			if (cnt_path[u][v] == 3){
				return 0;
			}
		}
	}

	build(adj);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1324 KB Output is correct
7 Correct 158 ms 25984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1324 KB Output is correct
7 Correct 158 ms 25984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1324 KB Output is correct
13 Correct 161 ms 25976 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 71 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 6676 KB Output is correct
21 Correct 162 ms 25996 KB Output is correct
22 Correct 159 ms 25924 KB Output is correct
23 Correct 161 ms 25996 KB Output is correct
24 Correct 159 ms 25984 KB Output is correct
25 Correct 67 ms 16000 KB Output is correct
26 Correct 65 ms 16012 KB Output is correct
27 Correct 162 ms 26000 KB Output is correct
28 Correct 158 ms 25964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 296 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 162 ms 27888 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 7 ms 1364 KB Output is correct
13 Correct 162 ms 28120 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 928 KB Output is correct
17 Correct 74 ms 18032 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 42 ms 7184 KB Output is correct
22 Correct 168 ms 27912 KB Output is correct
23 Correct 158 ms 27872 KB Output is correct
24 Correct 182 ms 27896 KB Output is correct
25 Correct 69 ms 18040 KB Output is correct
26 Correct 70 ms 18012 KB Output is correct
27 Correct 159 ms 27872 KB Output is correct
28 Correct 165 ms 28056 KB Output is correct
29 Correct 68 ms 18032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 40 ms 6704 KB Output is correct
5 Correct 162 ms 25988 KB Output is correct
6 Correct 160 ms 25992 KB Output is correct
7 Correct 162 ms 25972 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 6660 KB Output is correct
10 Correct 165 ms 25988 KB Output is correct
11 Correct 174 ms 25912 KB Output is correct
12 Correct 162 ms 25988 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 39 ms 6768 KB Output is correct
17 Correct 157 ms 25996 KB Output is correct
18 Correct 159 ms 25992 KB Output is correct
19 Correct 158 ms 25980 KB Output is correct
20 Correct 164 ms 25976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1324 KB Output is correct
7 Correct 158 ms 25984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1324 KB Output is correct
13 Correct 161 ms 25976 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 71 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 6676 KB Output is correct
21 Correct 162 ms 25996 KB Output is correct
22 Correct 159 ms 25924 KB Output is correct
23 Correct 161 ms 25996 KB Output is correct
24 Correct 159 ms 25984 KB Output is correct
25 Correct 67 ms 16000 KB Output is correct
26 Correct 65 ms 16012 KB Output is correct
27 Correct 162 ms 26000 KB Output is correct
28 Correct 158 ms 25964 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 162 ms 27888 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 162 ms 28120 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 928 KB Output is correct
45 Correct 74 ms 18032 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 42 ms 7184 KB Output is correct
50 Correct 168 ms 27912 KB Output is correct
51 Correct 158 ms 27872 KB Output is correct
52 Correct 182 ms 27896 KB Output is correct
53 Correct 69 ms 18040 KB Output is correct
54 Correct 70 ms 18012 KB Output is correct
55 Correct 159 ms 27872 KB Output is correct
56 Correct 165 ms 28056 KB Output is correct
57 Correct 68 ms 18032 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 3 ms 992 KB Output is correct
61 Correct 69 ms 18048 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 41 ms 7240 KB Output is correct
66 Correct 70 ms 18036 KB Output is correct
67 Correct 68 ms 18032 KB Output is correct
68 Correct 73 ms 17960 KB Output is correct
69 Correct 67 ms 18036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 7 ms 1324 KB Output is correct
7 Correct 158 ms 25984 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1324 KB Output is correct
13 Correct 161 ms 25976 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 844 KB Output is correct
17 Correct 71 ms 16132 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 6676 KB Output is correct
21 Correct 162 ms 25996 KB Output is correct
22 Correct 159 ms 25924 KB Output is correct
23 Correct 161 ms 25996 KB Output is correct
24 Correct 159 ms 25984 KB Output is correct
25 Correct 67 ms 16000 KB Output is correct
26 Correct 65 ms 16012 KB Output is correct
27 Correct 162 ms 26000 KB Output is correct
28 Correct 158 ms 25964 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 0 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 162 ms 27888 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 7 ms 1364 KB Output is correct
41 Correct 162 ms 28120 KB Output is correct
42 Correct 1 ms 300 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 928 KB Output is correct
45 Correct 74 ms 18032 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 42 ms 7184 KB Output is correct
50 Correct 168 ms 27912 KB Output is correct
51 Correct 158 ms 27872 KB Output is correct
52 Correct 182 ms 27896 KB Output is correct
53 Correct 69 ms 18040 KB Output is correct
54 Correct 70 ms 18012 KB Output is correct
55 Correct 159 ms 27872 KB Output is correct
56 Correct 165 ms 28056 KB Output is correct
57 Correct 68 ms 18032 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 40 ms 6704 KB Output is correct
62 Correct 162 ms 25988 KB Output is correct
63 Correct 160 ms 25992 KB Output is correct
64 Correct 162 ms 25972 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 40 ms 6660 KB Output is correct
67 Correct 165 ms 25988 KB Output is correct
68 Correct 174 ms 25912 KB Output is correct
69 Correct 162 ms 25988 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 39 ms 6768 KB Output is correct
74 Correct 157 ms 25996 KB Output is correct
75 Correct 159 ms 25992 KB Output is correct
76 Correct 158 ms 25980 KB Output is correct
77 Correct 164 ms 25976 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 3 ms 992 KB Output is correct
81 Correct 69 ms 18048 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 41 ms 7240 KB Output is correct
86 Correct 70 ms 18036 KB Output is correct
87 Correct 68 ms 18032 KB Output is correct
88 Correct 73 ms 17960 KB Output is correct
89 Correct 67 ms 18036 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 3 ms 980 KB Output is correct
93 Correct 71 ms 18164 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 4724 KB Output is correct
98 Correct 72 ms 18036 KB Output is correct
99 Correct 73 ms 18040 KB Output is correct
100 Correct 71 ms 18036 KB Output is correct
101 Correct 70 ms 18048 KB Output is correct
102 Correct 75 ms 18036 KB Output is correct
103 Correct 67 ms 18040 KB Output is correct
104 Correct 70 ms 18048 KB Output is correct
105 Correct 77 ms 18036 KB Output is correct