Submission #771519

# Submission time Handle Problem Language Result Execution time Memory
771519 2023-07-03T05:47:36 Z ono_de206 Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
240 ms 23988 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

// #define int long long
 
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int mxn = 1010;
int par[mxn];

int get(int x) {
	return (x == par[x] ? x : par[x] = get(par[x]));
}

void unite(int x, int y) {
	x = get(x); y = get(y);
	if(x == y) return;
	par[y] = x;
}

void setDsu(int n) {
	for(int i = 0; i < n; i++) {
		par[i] = i;
	}
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> answer(n, vector<int>(n));
	//1
	setDsu(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] != 0) {
				unite(i, j);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(get(i) == get(j) && p[i][j] == 0) {
				return 0;
			}
		}
	}
	//2
	setDsu(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 1) {
				unite(i, j);
			}
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(get(i) == get(j) && p[i][j] == 2) {
				return 0;
			}
		}
	}
	//3
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 3) {
				return 0;
			}
		}
	}
	//----------
	auto link = [&](int x, int y) -> void {
		if(x == y) return;
		answer[x][y] = answer[y][x] = 1;
	};
	vector<int> vis(n);
	for(int i = 0; i < n; i++) {
		if(vis[i]) continue;
		vector<int> line{i};
		vis[i] = 1;
		for(int j = i + 1; j < n; j++) {
			if(get(i) == get(j)) line.pb(j), vis[j] = 1;
		}
		set<int> s;
		for(int j = 0; j < n; j++) {
			if(p[i][j] == 2) {
				s.in(get(j));
			}
		}
		s.in(i);
		if(s.size() == 2) {
			return 0;
		}
		for(int j = 0; j + 1 < line.size(); j++) {
			link(line[j], line[j + 1]);
		}
		int ls = *s.rbegin();
		for(int x : s) {
			link(x, ls);
			ls = x;
		}
	}
	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:106:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for(int j = 0; j + 1 < line.size(); j++) {
      |                  ~~~~~~^~~~~~~~~~~~~
# 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 7 ms 1176 KB Output is correct
7 Correct 171 ms 22036 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 7 ms 1176 KB Output is correct
7 Correct 171 ms 22036 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 1164 KB Output is correct
13 Correct 160 ms 22024 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 74 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5760 KB Output is correct
21 Correct 173 ms 21992 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 187 ms 22032 KB Output is correct
24 Correct 169 ms 22040 KB Output is correct
25 Correct 65 ms 12036 KB Output is correct
26 Correct 64 ms 12052 KB Output is correct
27 Correct 175 ms 22008 KB Output is correct
28 Correct 162 ms 22036 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 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 9 ms 1108 KB Output is correct
9 Correct 200 ms 22012 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 9 ms 1108 KB Output is correct
13 Correct 240 ms 22044 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 75 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 44 ms 5708 KB Output is correct
22 Correct 189 ms 21980 KB Output is correct
23 Correct 173 ms 22032 KB Output is correct
24 Correct 203 ms 22024 KB Output is correct
25 Correct 78 ms 12180 KB Output is correct
26 Correct 88 ms 12036 KB Output is correct
27 Correct 167 ms 22040 KB Output is correct
28 Correct 199 ms 22024 KB Output is correct
29 Correct 84 ms 12040 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 42 ms 6240 KB Output is correct
5 Correct 168 ms 22600 KB Output is correct
6 Correct 164 ms 22552 KB Output is correct
7 Correct 173 ms 22536 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 41 ms 6248 KB Output is correct
10 Correct 181 ms 22580 KB Output is correct
11 Correct 165 ms 22604 KB Output is correct
12 Correct 222 ms 22604 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 43 ms 6196 KB Output is correct
17 Correct 174 ms 23988 KB Output is correct
18 Correct 167 ms 23948 KB Output is correct
19 Correct 172 ms 23928 KB Output is correct
20 Correct 160 ms 23916 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 7 ms 1176 KB Output is correct
7 Correct 171 ms 22036 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 1164 KB Output is correct
13 Correct 160 ms 22024 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 74 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5760 KB Output is correct
21 Correct 173 ms 21992 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 187 ms 22032 KB Output is correct
24 Correct 169 ms 22040 KB Output is correct
25 Correct 65 ms 12036 KB Output is correct
26 Correct 64 ms 12052 KB Output is correct
27 Correct 175 ms 22008 KB Output is correct
28 Correct 162 ms 22036 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 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 9 ms 1108 KB Output is correct
37 Correct 200 ms 22012 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 240 ms 22044 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 75 ms 12048 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 44 ms 5708 KB Output is correct
50 Correct 189 ms 21980 KB Output is correct
51 Correct 173 ms 22032 KB Output is correct
52 Correct 203 ms 22024 KB Output is correct
53 Correct 78 ms 12180 KB Output is correct
54 Correct 88 ms 12036 KB Output is correct
55 Correct 167 ms 22040 KB Output is correct
56 Correct 199 ms 22024 KB Output is correct
57 Correct 84 ms 12040 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 852 KB Output is correct
61 Correct 81 ms 12960 KB Output is correct
62 Correct 1 ms 300 KB Output is correct
63 Correct 1 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 41 ms 6248 KB Output is correct
66 Correct 70 ms 14028 KB Output is correct
67 Correct 73 ms 14080 KB Output is correct
68 Correct 64 ms 14068 KB Output is correct
69 Correct 67 ms 14088 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 7 ms 1176 KB Output is correct
7 Correct 171 ms 22036 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 1164 KB Output is correct
13 Correct 160 ms 22024 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 74 ms 12048 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 41 ms 5760 KB Output is correct
21 Correct 173 ms 21992 KB Output is correct
22 Correct 174 ms 22028 KB Output is correct
23 Correct 187 ms 22032 KB Output is correct
24 Correct 169 ms 22040 KB Output is correct
25 Correct 65 ms 12036 KB Output is correct
26 Correct 64 ms 12052 KB Output is correct
27 Correct 175 ms 22008 KB Output is correct
28 Correct 162 ms 22036 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 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 9 ms 1108 KB Output is correct
37 Correct 200 ms 22012 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 9 ms 1108 KB Output is correct
41 Correct 240 ms 22044 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 75 ms 12048 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 44 ms 5708 KB Output is correct
50 Correct 189 ms 21980 KB Output is correct
51 Correct 173 ms 22032 KB Output is correct
52 Correct 203 ms 22024 KB Output is correct
53 Correct 78 ms 12180 KB Output is correct
54 Correct 88 ms 12036 KB Output is correct
55 Correct 167 ms 22040 KB Output is correct
56 Correct 199 ms 22024 KB Output is correct
57 Correct 84 ms 12040 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 42 ms 6240 KB Output is correct
62 Correct 168 ms 22600 KB Output is correct
63 Correct 164 ms 22552 KB Output is correct
64 Correct 173 ms 22536 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 41 ms 6248 KB Output is correct
67 Correct 181 ms 22580 KB Output is correct
68 Correct 165 ms 22604 KB Output is correct
69 Correct 222 ms 22604 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 304 KB Output is correct
72 Correct 1 ms 304 KB Output is correct
73 Correct 43 ms 6196 KB Output is correct
74 Correct 174 ms 23988 KB Output is correct
75 Correct 167 ms 23948 KB Output is correct
76 Correct 172 ms 23928 KB Output is correct
77 Correct 160 ms 23916 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 852 KB Output is correct
81 Correct 81 ms 12960 KB Output is correct
82 Correct 1 ms 300 KB Output is correct
83 Correct 1 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 41 ms 6248 KB Output is correct
86 Correct 70 ms 14028 KB Output is correct
87 Correct 73 ms 14080 KB Output is correct
88 Correct 64 ms 14068 KB Output is correct
89 Correct 67 ms 14088 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 304 KB Output is correct
92 Correct 4 ms 852 KB Output is correct
93 Correct 71 ms 13980 KB Output is correct
94 Correct 1 ms 212 KB Output is correct
95 Correct 1 ms 308 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 17 ms 3708 KB Output is correct
98 Correct 68 ms 14088 KB Output is correct
99 Correct 67 ms 14072 KB Output is correct
100 Correct 78 ms 14160 KB Output is correct
101 Correct 67 ms 14028 KB Output is correct
102 Correct 75 ms 14072 KB Output is correct
103 Correct 84 ms 14092 KB Output is correct
104 Correct 88 ms 14072 KB Output is correct
105 Correct 80 ms 14032 KB Output is correct