Submission #733981

# Submission time Handle Problem Language Result Execution time Memory
733981 2023-05-01T12:46:14 Z vjudge1 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
258 ms 22220 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 3;

struct DSU{
	int par[MAX];
	int find(int u){
		if(par[u] < 0) return u;
		return par[u] = find(par[u]);
	}
	bool unite(int u, int v){
		u = find(u), v = find(v);
		if(u == v) return false;
		if(par[u] > par[v]) swap(u, v);
		par[u] += par[v];
		par[v] = u;
		return true;
	}
	DSU(){
		memset(par, -1, sizeof(par));
	}
};
int construct(vector<vector<int>> p) 
{
	for(auto i : p) for(auto j : i) if(j == 3) return 0;
	DSU dsu1, dsu2;
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n, 0));
	int mark[n] = {0};
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[i][j] == 0 && dsu1.find(i) == dsu1.find(j)) return 0;
			if(p[i][j] != 1) continue;
			if(dsu1.unite(i, j)){
				answer[i][j] = answer[j][i] = 1;
			}
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(p[dsu1.find(i)][dsu1.find(j)] == 2){
				dsu2.unite(dsu1.find(i), dsu1.find(j));
			} 
		}
	}
	for (int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(dsu2.find(dsu1.find(i)) == dsu2.find(dsu1.find(j)) && p[dsu1.find(i)][dsu1.find(j)] == 0) return 0;
		}
	}
	vector<int> comp[n];
	for(int i = 0; i < n; i++){
		if(mark[dsu1.find(i)]) continue;
		mark[dsu1.find(i)] = 1;
		comp[dsu2.find(dsu1.find(i))].push_back(dsu1.find(i));
	}
	for(auto &v : comp){
		if(v.size() == 2) return 0;
		if(v.size() < 2) continue;
		for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
		answer[v[v.size() - 1]][v[0]] = answer[v[0]][v[v.size() - 1]] = 1;
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int j = 0; j < v.size() - 1; j++) answer[v[j]][v[j + 1]] = answer[v[j + 1]][v[j]] = 1;
      |                  ~~^~~~~~~~~~~~~~
# 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 212 KB Output is correct
6 Correct 8 ms 1096 KB Output is correct
7 Correct 198 ms 22076 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 212 KB Output is correct
6 Correct 8 ms 1096 KB Output is correct
7 Correct 198 ms 22076 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 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 183 ms 22032 KB Output is correct
14 Correct 1 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 76 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5740 KB Output is correct
21 Correct 205 ms 22032 KB Output is correct
22 Correct 212 ms 22048 KB Output is correct
23 Correct 206 ms 21968 KB Output is correct
24 Correct 204 ms 21992 KB Output is correct
25 Correct 75 ms 12048 KB Output is correct
26 Correct 102 ms 12048 KB Output is correct
27 Correct 210 ms 22096 KB Output is correct
28 Correct 194 ms 22220 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 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 8 ms 1204 KB Output is correct
9 Correct 183 ms 22048 KB Output is correct
10 Correct 1 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 187 ms 22040 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 106 ms 12144 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 51 ms 5764 KB Output is correct
22 Correct 184 ms 22016 KB Output is correct
23 Correct 188 ms 22024 KB Output is correct
24 Correct 204 ms 22068 KB Output is correct
25 Correct 87 ms 12180 KB Output is correct
26 Correct 86 ms 12032 KB Output is correct
27 Correct 202 ms 21988 KB Output is correct
28 Correct 258 ms 21992 KB Output is correct
29 Correct 98 ms 12236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 49 ms 5752 KB Output is correct
5 Correct 194 ms 22116 KB Output is correct
6 Correct 208 ms 22020 KB Output is correct
7 Correct 228 ms 21960 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 49 ms 5736 KB Output is correct
10 Correct 187 ms 22068 KB Output is correct
11 Correct 189 ms 22092 KB Output is correct
12 Correct 223 ms 22032 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 49 ms 5744 KB Output is correct
17 Correct 227 ms 21984 KB Output is correct
18 Correct 204 ms 22140 KB Output is correct
19 Correct 196 ms 21964 KB Output is correct
20 Correct 198 ms 22032 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 212 KB Output is correct
6 Correct 8 ms 1096 KB Output is correct
7 Correct 198 ms 22076 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 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 183 ms 22032 KB Output is correct
14 Correct 1 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 76 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5740 KB Output is correct
21 Correct 205 ms 22032 KB Output is correct
22 Correct 212 ms 22048 KB Output is correct
23 Correct 206 ms 21968 KB Output is correct
24 Correct 204 ms 21992 KB Output is correct
25 Correct 75 ms 12048 KB Output is correct
26 Correct 102 ms 12048 KB Output is correct
27 Correct 210 ms 22096 KB Output is correct
28 Correct 194 ms 22220 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 183 ms 22048 KB Output is correct
38 Correct 1 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 187 ms 22040 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 106 ms 12144 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 51 ms 5764 KB Output is correct
50 Correct 184 ms 22016 KB Output is correct
51 Correct 188 ms 22024 KB Output is correct
52 Correct 204 ms 22068 KB Output is correct
53 Correct 87 ms 12180 KB Output is correct
54 Correct 86 ms 12032 KB Output is correct
55 Correct 202 ms 21988 KB Output is correct
56 Correct 258 ms 21992 KB Output is correct
57 Correct 98 ms 12236 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 107 ms 12036 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 56 ms 5756 KB Output is correct
66 Correct 77 ms 12032 KB Output is correct
67 Correct 73 ms 12048 KB Output is correct
68 Correct 85 ms 12044 KB Output is correct
69 Correct 78 ms 12168 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 212 KB Output is correct
6 Correct 8 ms 1096 KB Output is correct
7 Correct 198 ms 22076 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 0 ms 212 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 183 ms 22032 KB Output is correct
14 Correct 1 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 76 ms 12048 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 48 ms 5740 KB Output is correct
21 Correct 205 ms 22032 KB Output is correct
22 Correct 212 ms 22048 KB Output is correct
23 Correct 206 ms 21968 KB Output is correct
24 Correct 204 ms 21992 KB Output is correct
25 Correct 75 ms 12048 KB Output is correct
26 Correct 102 ms 12048 KB Output is correct
27 Correct 210 ms 22096 KB Output is correct
28 Correct 194 ms 22220 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 8 ms 1204 KB Output is correct
37 Correct 183 ms 22048 KB Output is correct
38 Correct 1 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 187 ms 22040 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 106 ms 12144 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 51 ms 5764 KB Output is correct
50 Correct 184 ms 22016 KB Output is correct
51 Correct 188 ms 22024 KB Output is correct
52 Correct 204 ms 22068 KB Output is correct
53 Correct 87 ms 12180 KB Output is correct
54 Correct 86 ms 12032 KB Output is correct
55 Correct 202 ms 21988 KB Output is correct
56 Correct 258 ms 21992 KB Output is correct
57 Correct 98 ms 12236 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 288 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 49 ms 5752 KB Output is correct
62 Correct 194 ms 22116 KB Output is correct
63 Correct 208 ms 22020 KB Output is correct
64 Correct 228 ms 21960 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 49 ms 5736 KB Output is correct
67 Correct 187 ms 22068 KB Output is correct
68 Correct 189 ms 22092 KB Output is correct
69 Correct 223 ms 22032 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 49 ms 5744 KB Output is correct
74 Correct 227 ms 21984 KB Output is correct
75 Correct 204 ms 22140 KB Output is correct
76 Correct 196 ms 21964 KB Output is correct
77 Correct 198 ms 22032 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 107 ms 12036 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 56 ms 5756 KB Output is correct
86 Correct 77 ms 12032 KB Output is correct
87 Correct 73 ms 12048 KB Output is correct
88 Correct 85 ms 12044 KB Output is correct
89 Correct 78 ms 12168 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 1 ms 212 KB Output is correct
92 Correct 4 ms 596 KB Output is correct
93 Correct 72 ms 8068 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 1 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 18 ms 2196 KB Output is correct
98 Correct 67 ms 8068 KB Output is correct
99 Correct 70 ms 8072 KB Output is correct
100 Correct 70 ms 8064 KB Output is correct
101 Correct 68 ms 8072 KB Output is correct
102 Correct 77 ms 8068 KB Output is correct
103 Correct 78 ms 8076 KB Output is correct
104 Correct 70 ms 8068 KB Output is correct
105 Correct 81 ms 8068 KB Output is correct