Submission #576702

# Submission time Handle Problem Language Result Execution time Memory
576702 2022-06-13T09:35:27 Z Vanilla Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
412 ms 24180 KB
#include <bits/stdc++.h>
#include "supertrees.h"
using namespace std;
const int maxn = 1002;
int d[maxn];

int dad (int x) {
	return d[x] = (x == d[x] ? x: dad(d[x]));
}

void merge (int a, int b){
	a = dad(a);
	b = dad(b);
	d[b] = a;
}


int construct(vector<vector<int>> p) {
	int n = p.size();
	vector <vector <int> > b (n, vector <int> (n, 0));
	for (int i = 0; i < n; i++){
		d[i] = i;
	}
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			if (p[i][j] == 3) return 0;
			if (p[i][j] == 1 && dad(i) != dad(j)) {
				b[i][j] = b[j][i] = 1;
				merge(i,j);
			}
		}
	}
	for (int i = 0; i < n; i++){
		vector <int> v;
		v.push_back(dad(i));
		for (int j = i + 1; j < n; j++){
			if (p[i][j] == 2 && dad(i) != dad(j)) {
				v.push_back(dad(j));
				merge(i, j);
			}
		}
		if (v.size() == 2) return 0;
		if (v.size() > 1)
			for (int i = 0; i < v.size(); i++){
				int p1 = v[i], p2 = v[(i + 1) % v.size()];
				b[p1][p2] = b[p2][p1] = 1;
			}
	}
	for (int i = 0; i < n; i++){
		for (int j = i + 1; j < n; j++){
			for (int k = j + 1; k < n; k++){
				if (p[i][j] == 1 && p[j][k] == 1 && p[i][k] != 1) return 0;
			}
			if (p[i][j] == 0 && dad(i) == dad(j)) return 0;
		}
	}
	build(b);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    for (int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# 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 1 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 11 ms 1140 KB Output is correct
7 Correct 292 ms 21964 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 1 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 11 ms 1140 KB Output is correct
7 Correct 292 ms 21964 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 241 ms 22060 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 88 ms 12136 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 53 ms 5720 KB Output is correct
21 Correct 270 ms 22020 KB Output is correct
22 Correct 235 ms 22004 KB Output is correct
23 Correct 378 ms 22040 KB Output is correct
24 Correct 302 ms 22024 KB Output is correct
25 Correct 73 ms 12048 KB Output is correct
26 Correct 102 ms 12036 KB Output is correct
27 Correct 412 ms 21984 KB Output is correct
28 Correct 247 ms 21960 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 296 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 11 ms 1120 KB Output is correct
9 Correct 240 ms 22032 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 269 ms 22000 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 78 ms 14084 KB Output is correct
18 Correct 1 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 59 ms 6160 KB Output is correct
22 Correct 240 ms 23948 KB Output is correct
23 Correct 244 ms 23924 KB Output is correct
24 Correct 254 ms 23928 KB Output is correct
25 Correct 71 ms 14028 KB Output is correct
26 Correct 72 ms 14072 KB Output is correct
27 Correct 242 ms 23928 KB Output is correct
28 Correct 270 ms 24180 KB Output is correct
29 Correct 81 ms 14004 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 55 ms 5708 KB Output is correct
5 Correct 284 ms 21996 KB Output is correct
6 Correct 259 ms 21960 KB Output is correct
7 Correct 389 ms 21992 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 54 ms 5660 KB Output is correct
10 Correct 270 ms 22020 KB Output is correct
11 Correct 249 ms 21968 KB Output is correct
12 Correct 243 ms 21964 KB Output is correct
13 Correct 0 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 56 ms 5664 KB Output is correct
17 Correct 244 ms 21960 KB Output is correct
18 Correct 245 ms 22004 KB Output is correct
19 Correct 239 ms 22024 KB Output is correct
20 Correct 241 ms 22076 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 1 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 11 ms 1140 KB Output is correct
7 Correct 292 ms 21964 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 241 ms 22060 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 88 ms 12136 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 53 ms 5720 KB Output is correct
21 Correct 270 ms 22020 KB Output is correct
22 Correct 235 ms 22004 KB Output is correct
23 Correct 378 ms 22040 KB Output is correct
24 Correct 302 ms 22024 KB Output is correct
25 Correct 73 ms 12048 KB Output is correct
26 Correct 102 ms 12036 KB Output is correct
27 Correct 412 ms 21984 KB Output is correct
28 Correct 247 ms 21960 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 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 0 ms 296 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 11 ms 1120 KB Output is correct
37 Correct 240 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 269 ms 22000 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 78 ms 14084 KB Output is correct
46 Correct 1 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 59 ms 6160 KB Output is correct
50 Correct 240 ms 23948 KB Output is correct
51 Correct 244 ms 23924 KB Output is correct
52 Correct 254 ms 23928 KB Output is correct
53 Correct 71 ms 14028 KB Output is correct
54 Correct 72 ms 14072 KB Output is correct
55 Correct 242 ms 23928 KB Output is correct
56 Correct 270 ms 24180 KB Output is correct
57 Correct 81 ms 14004 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 828 KB Output is correct
61 Correct 85 ms 14092 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 300 KB Output is correct
65 Correct 55 ms 6260 KB Output is correct
66 Correct 74 ms 14008 KB Output is correct
67 Correct 75 ms 14068 KB Output is correct
68 Correct 72 ms 14108 KB Output is correct
69 Correct 75 ms 14000 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 1 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 11 ms 1140 KB Output is correct
7 Correct 292 ms 21964 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 10 ms 1108 KB Output is correct
13 Correct 241 ms 22060 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 88 ms 12136 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 53 ms 5720 KB Output is correct
21 Correct 270 ms 22020 KB Output is correct
22 Correct 235 ms 22004 KB Output is correct
23 Correct 378 ms 22040 KB Output is correct
24 Correct 302 ms 22024 KB Output is correct
25 Correct 73 ms 12048 KB Output is correct
26 Correct 102 ms 12036 KB Output is correct
27 Correct 412 ms 21984 KB Output is correct
28 Correct 247 ms 21960 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 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 0 ms 296 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 11 ms 1120 KB Output is correct
37 Correct 240 ms 22032 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 269 ms 22000 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 78 ms 14084 KB Output is correct
46 Correct 1 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 59 ms 6160 KB Output is correct
50 Correct 240 ms 23948 KB Output is correct
51 Correct 244 ms 23924 KB Output is correct
52 Correct 254 ms 23928 KB Output is correct
53 Correct 71 ms 14028 KB Output is correct
54 Correct 72 ms 14072 KB Output is correct
55 Correct 242 ms 23928 KB Output is correct
56 Correct 270 ms 24180 KB Output is correct
57 Correct 81 ms 14004 KB Output is correct
58 Correct 1 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 55 ms 5708 KB Output is correct
62 Correct 284 ms 21996 KB Output is correct
63 Correct 259 ms 21960 KB Output is correct
64 Correct 389 ms 21992 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 54 ms 5660 KB Output is correct
67 Correct 270 ms 22020 KB Output is correct
68 Correct 249 ms 21968 KB Output is correct
69 Correct 243 ms 21964 KB Output is correct
70 Correct 0 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 56 ms 5664 KB Output is correct
74 Correct 244 ms 21960 KB Output is correct
75 Correct 245 ms 22004 KB Output is correct
76 Correct 239 ms 22024 KB Output is correct
77 Correct 241 ms 22076 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 828 KB Output is correct
81 Correct 85 ms 14092 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 300 KB Output is correct
85 Correct 55 ms 6260 KB Output is correct
86 Correct 74 ms 14008 KB Output is correct
87 Correct 75 ms 14068 KB Output is correct
88 Correct 72 ms 14108 KB Output is correct
89 Correct 75 ms 14000 KB Output is correct
90 Correct 1 ms 300 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 804 KB Output is correct
93 Correct 81 ms 14028 KB Output is correct
94 Correct 1 ms 300 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 304 KB Output is correct
97 Correct 20 ms 3716 KB Output is correct
98 Correct 75 ms 14076 KB Output is correct
99 Correct 78 ms 14072 KB Output is correct
100 Correct 71 ms 14088 KB Output is correct
101 Correct 71 ms 14072 KB Output is correct
102 Correct 71 ms 14088 KB Output is correct
103 Correct 78 ms 14028 KB Output is correct
104 Correct 79 ms 14068 KB Output is correct
105 Correct 76 ms 14068 KB Output is correct