Submission #823028

# Submission time Handle Problem Language Result Execution time Memory
823028 2023-08-12T07:10:38 Z NothingXD Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
217 ms 30020 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out(){cerr<<endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
	cerr << H << ' ';
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin() x.end()
#define MP(x, y) make_pair(x, y)

const int maxn = 1e3 + 10;

int n, p[maxn][maxn], dsu[maxn], comp[maxn];
int ans[maxn][maxn];
vector<int> ver[maxn];
int getdsu(int v){
	return (dsu[v] == -1? v: dsu[v] = getdsu(dsu[v]));
}

void merge(int u, int v){
	if ((u = getdsu(u)) == (v = getdsu(v))) return;
	ans[u][v] = ans[v][u] = 1;
	dsu[u] = v;
}

bool merge2(int u, int v){
//	debug(u, v);
	u = comp[u], v = comp[v];
	if (u == v) return true;
	for (auto x: ver[u]){
		for (auto y: ver[v]){
			if (p[x][y] != 2) return false;
		}
	}
	for (auto x: ver[v]){
		if (x == v) continue;
		ver[u].push_back(x);
		comp[x] = u;
	}
	ver[u].push_back(v);
	comp[v] = u;
	return true;
}

int construct(vector<vector<int>> P) {
	n = P.size();
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			p[i][j] = P[i][j];
		}
	}
	memset(dsu, -1, sizeof dsu);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] != p[j][i]) return 0;
			if (p[i][j] == 1) merge(i, j);
		}
	}
//	debug(1);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] != 1 && getdsu(i) == getdsu(j)) return 0;
		}
	}
//	debug(2);
	for (int i = 0; i < n; i++){
		int x = getdsu(i);
//		debug(i, x);
		ver[x].push_back(i);
		comp[i] = x;
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (p[i][j] == 2){
				if (!merge2(i, j)) return 0;
			}
		}
	}
//	debug(3);
	for (int i = 0; i < n; i++){
		ver[i].clear();
	}
	for (int i = 0; i < n; i++){
		if (dsu[i] == -1){
//			debug(i, comp[i]);
			ver[comp[i]].push_back(i);
		}
	}
	for (int i = 0; i < n; i++){
//		debug(i, ver[i].size());
		if (ver[i].size() < 2) continue;
		if (ver[i].size() == 2) return 0;
		for (int j = 1; j < ver[i].size(); j++){
			ans[ver[i][j-1]][ver[i][j]] = ans[ver[i][j]][ver[i][j-1]] = 1;
		}
		ans[ver[i][0]][ver[i].back()] = ans[ver[i].back()][ver[i][0]] = 1;
	}
//	debug(4);
	vector<vector<int>> res(n);
	for (int i = 0; i < n; i++){
		res[i].resize(n);
		for (int j = 0; j < n; j++){
			res[i][j] = ans[i][j];
		}
	}
	build(res);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:105:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |   for (int j = 1; j < ver[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2756 KB Output is correct
7 Correct 172 ms 30016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2756 KB Output is correct
7 Correct 172 ms 30016 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 175 ms 26004 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 2132 KB Output is correct
17 Correct 77 ms 16056 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 41 ms 9560 KB Output is correct
21 Correct 162 ms 29908 KB Output is correct
22 Correct 161 ms 29488 KB Output is correct
23 Correct 167 ms 29900 KB Output is correct
24 Correct 174 ms 26288 KB Output is correct
25 Correct 76 ms 16040 KB Output is correct
26 Correct 68 ms 15656 KB Output is correct
27 Correct 166 ms 29988 KB Output is correct
28 Correct 159 ms 26292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 7 ms 2004 KB Output is correct
9 Correct 167 ms 26056 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2772 KB Output is correct
13 Correct 163 ms 30004 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 3 ms 1456 KB Output is correct
17 Correct 71 ms 12208 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 41 ms 9620 KB Output is correct
22 Correct 161 ms 29992 KB Output is correct
23 Correct 165 ms 29916 KB Output is correct
24 Correct 166 ms 30020 KB Output is correct
25 Correct 67 ms 12344 KB Output is correct
26 Correct 66 ms 12216 KB Output is correct
27 Correct 159 ms 29860 KB Output is correct
28 Correct 171 ms 30004 KB Output is correct
29 Correct 75 ms 12344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 41 ms 9532 KB Output is correct
5 Correct 217 ms 29924 KB Output is correct
6 Correct 165 ms 29480 KB Output is correct
7 Correct 167 ms 29900 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 41 ms 9600 KB Output is correct
10 Correct 189 ms 30016 KB Output is correct
11 Correct 161 ms 29904 KB Output is correct
12 Correct 169 ms 30016 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 41 ms 9536 KB Output is correct
17 Correct 174 ms 29996 KB Output is correct
18 Correct 180 ms 29876 KB Output is correct
19 Correct 162 ms 29860 KB Output is correct
20 Correct 162 ms 26320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2756 KB Output is correct
7 Correct 172 ms 30016 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 175 ms 26004 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 2132 KB Output is correct
17 Correct 77 ms 16056 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 41 ms 9560 KB Output is correct
21 Correct 162 ms 29908 KB Output is correct
22 Correct 161 ms 29488 KB Output is correct
23 Correct 167 ms 29900 KB Output is correct
24 Correct 174 ms 26288 KB Output is correct
25 Correct 76 ms 16040 KB Output is correct
26 Correct 68 ms 15656 KB Output is correct
27 Correct 166 ms 29988 KB Output is correct
28 Correct 159 ms 26292 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 2004 KB Output is correct
37 Correct 167 ms 26056 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 2772 KB Output is correct
41 Correct 163 ms 30004 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 3 ms 1456 KB Output is correct
45 Correct 71 ms 12208 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 9620 KB Output is correct
50 Correct 161 ms 29992 KB Output is correct
51 Correct 165 ms 29916 KB Output is correct
52 Correct 166 ms 30020 KB Output is correct
53 Correct 67 ms 12344 KB Output is correct
54 Correct 66 ms 12216 KB Output is correct
55 Correct 159 ms 29860 KB Output is correct
56 Correct 171 ms 30004 KB Output is correct
57 Correct 75 ms 12344 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 4 ms 2132 KB Output is correct
61 Correct 76 ms 16052 KB Output is correct
62 Correct 0 ms 340 KB Output is correct
63 Correct 0 ms 340 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 41 ms 9588 KB Output is correct
66 Correct 76 ms 12192 KB Output is correct
67 Correct 79 ms 14256 KB Output is correct
68 Correct 103 ms 14248 KB Output is correct
69 Correct 70 ms 12324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 8 ms 2756 KB Output is correct
7 Correct 172 ms 30016 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 2004 KB Output is correct
13 Correct 175 ms 26004 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 5 ms 2132 KB Output is correct
17 Correct 77 ms 16056 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 41 ms 9560 KB Output is correct
21 Correct 162 ms 29908 KB Output is correct
22 Correct 161 ms 29488 KB Output is correct
23 Correct 167 ms 29900 KB Output is correct
24 Correct 174 ms 26288 KB Output is correct
25 Correct 76 ms 16040 KB Output is correct
26 Correct 68 ms 15656 KB Output is correct
27 Correct 166 ms 29988 KB Output is correct
28 Correct 159 ms 26292 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 2004 KB Output is correct
37 Correct 167 ms 26056 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 2772 KB Output is correct
41 Correct 163 ms 30004 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 3 ms 1456 KB Output is correct
45 Correct 71 ms 12208 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 41 ms 9620 KB Output is correct
50 Correct 161 ms 29992 KB Output is correct
51 Correct 165 ms 29916 KB Output is correct
52 Correct 166 ms 30020 KB Output is correct
53 Correct 67 ms 12344 KB Output is correct
54 Correct 66 ms 12216 KB Output is correct
55 Correct 159 ms 29860 KB Output is correct
56 Correct 171 ms 30004 KB Output is correct
57 Correct 75 ms 12344 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 0 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 41 ms 9532 KB Output is correct
62 Correct 217 ms 29924 KB Output is correct
63 Correct 165 ms 29480 KB Output is correct
64 Correct 167 ms 29900 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 41 ms 9600 KB Output is correct
67 Correct 189 ms 30016 KB Output is correct
68 Correct 161 ms 29904 KB Output is correct
69 Correct 169 ms 30016 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 41 ms 9536 KB Output is correct
74 Correct 174 ms 29996 KB Output is correct
75 Correct 180 ms 29876 KB Output is correct
76 Correct 162 ms 29860 KB Output is correct
77 Correct 162 ms 26320 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 4 ms 2132 KB Output is correct
81 Correct 76 ms 16052 KB Output is correct
82 Correct 0 ms 340 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 41 ms 9588 KB Output is correct
86 Correct 76 ms 12192 KB Output is correct
87 Correct 79 ms 14256 KB Output is correct
88 Correct 103 ms 14248 KB Output is correct
89 Correct 70 ms 12324 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 0 ms 340 KB Output is correct
92 Correct 4 ms 2132 KB Output is correct
93 Correct 71 ms 16052 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Incorrect 0 ms 340 KB Answer gives possible 1 while actual possible 0
96 Halted 0 ms 0 KB -