Submission #771570

# Submission time Handle Problem Language Result Execution time Memory
771570 2023-07-03T06:31:54 Z khshg Connecting Supertrees (IOI20_supertrees) C++14
56 / 100
184 ms 22116 KB
#include"supertrees.h"
#include<bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> P, ans, D;
vector<int> par;

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

int unite(int x, int y) {
	x = parent(x);
	y = parent(y);
	if(x == y) return 1;
	if((int)D[x].size() < (int)D[y].size()) swap(x, y);
	for(auto& u : D[x]) for(auto& v : D[y]) {
		if(P[u][v] != 1) return 0;
	}
	for(auto& u : D[y]) D[x].emplace_back(u);
	par[y] = x;
	return 1;
}

int construct(vector<vector<int>> _p) {
	swap(P, _p);
	N = (int)P.size();
	D.resize(N);
	par.resize(N); iota(begin(par), end(par), 0);
	for(int i = 0; i < N; ++i) D[i].push_back(i);
	for(int i = 0; i < N; ++i) {
		for(int j = i + 1; j < N; ++j) {
			if(P[i][j] == 1) {
				if(!unite(i, j)) {
					return 0;
				}
			}
		}
	}
	vector<int> comps;
	{
		set<int> s;
		for(int i = 0; i < N; ++i) {
			s.insert(parent(i));
		}
		comps = vector<int>(begin(s), end(s));
	}
	ans = vector<vector<int>>(N, vector<int>(N, 0));
	for(auto& u : comps) {
		for(int i = 0; i < (int)D[u].size(); ++i) {
			if(D[u][i] == u) swap(D[u][i], D[u][0]);
		}
		for(int i = 1; i < (int)D[u].size(); ++i) {
			ans[u][D[u][i]] = 1;
			ans[D[u][i]][u] = 1;
		}
	}
	vector<bool> did(N);
	for(int i = 0; i < N; ++i) {
		if(did[parent(i)]) continue;
		did[parent(i)] = 1;
		vector<int> ids = {i};
		for(int j = i + 1; j < N; ++j) {
			if(P[i][j] == 2) {
				ids.push_back(j);
			}
		}
		if((int)ids.size() == 1) continue;
		{
			set<int> s;
			for(auto& u : ids) {
				s.insert(parent(u));
			}
			ids = vector<int>(begin(s), end(s));
		}
		ans[ids[0]][ids.back()] = 1;
		ans[ids.back()][ids[0]] = 1;
		for(int i = 1; i < (int)ids.size(); ++i) {
			did[ids[i]] = 1;
			ans[ids[i]][ids[i - 1]] = 1;
			ans[ids[i - 1]][ids[i]] = 1;
		}
	}
	build(ans);
	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 6 ms 1108 KB Output is correct
7 Correct 153 ms 22024 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 6 ms 1108 KB Output is correct
7 Correct 153 ms 22024 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 1108 KB Output is correct
13 Correct 172 ms 22020 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 596 KB Output is correct
17 Correct 68 ms 8192 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 5684 KB Output is correct
21 Correct 160 ms 22020 KB Output is correct
22 Correct 151 ms 22024 KB Output is correct
23 Correct 173 ms 22060 KB Output is correct
24 Correct 160 ms 22108 KB Output is correct
25 Correct 73 ms 8196 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 159 ms 21988 KB Output is correct
28 Correct 155 ms 22080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 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 5780 KB Output is correct
5 Correct 152 ms 22000 KB Output is correct
6 Correct 156 ms 22012 KB Output is correct
7 Correct 180 ms 22104 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 36 ms 5772 KB Output is correct
10 Correct 153 ms 22016 KB Output is correct
11 Correct 153 ms 22076 KB Output is correct
12 Correct 165 ms 22024 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 37 ms 5736 KB Output is correct
17 Correct 184 ms 22024 KB Output is correct
18 Correct 145 ms 22116 KB Output is correct
19 Correct 146 ms 21992 KB Output is correct
20 Correct 144 ms 22000 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 6 ms 1108 KB Output is correct
7 Correct 153 ms 22024 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 1108 KB Output is correct
13 Correct 172 ms 22020 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 596 KB Output is correct
17 Correct 68 ms 8192 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 5684 KB Output is correct
21 Correct 160 ms 22020 KB Output is correct
22 Correct 151 ms 22024 KB Output is correct
23 Correct 173 ms 22060 KB Output is correct
24 Correct 160 ms 22108 KB Output is correct
25 Correct 73 ms 8196 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 159 ms 21988 KB Output is correct
28 Correct 155 ms 22080 KB Output is correct
29 Correct 1 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 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 6 ms 1108 KB Output is correct
7 Correct 153 ms 22024 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 1108 KB Output is correct
13 Correct 172 ms 22020 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 596 KB Output is correct
17 Correct 68 ms 8192 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 5684 KB Output is correct
21 Correct 160 ms 22020 KB Output is correct
22 Correct 151 ms 22024 KB Output is correct
23 Correct 173 ms 22060 KB Output is correct
24 Correct 160 ms 22108 KB Output is correct
25 Correct 73 ms 8196 KB Output is correct
26 Correct 59 ms 8192 KB Output is correct
27 Correct 159 ms 21988 KB Output is correct
28 Correct 155 ms 22080 KB Output is correct
29 Correct 1 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 Incorrect 0 ms 212 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -