Submission #873384

# Submission time Handle Problem Language Result Execution time Memory
873384 2023-11-15T01:51:23 Z bobbilyking Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
176 ms 24216 KB
#include "supertrees.h"
using namespace std;
#include <bits/stdc++.h>
using ll=long long;

#define F(i, l, r) for (ll i = (l); i < ll(r); ++i)
bool vis[1010];
vector<ll> comp;

struct info {
	vector<ll> twos;
	vector<vector<ll>> ones;
};

vector<info> glob;

void dfs(ll i, vector<vector<int>>& p) {
	if (vis[i]) return;
	vis[i] = 1;
	comp.push_back(i);
	F(j, 0, p.size()) if (p[i][j]) dfs(j, p);
}

ll dsu[1010];
vector<ll> st[1010];
ll find(ll i) {
	return dsu[i] == i ? i: dsu[i] = find(dsu[i]);
}


bool my_build(std::vector<std::vector<int>>& b) {
	for (auto &[twos, ones]: glob) {
		if (!twos.size()) if (ones.size() != 1) return false; // if no cycles, y'all should be happy wtf bruther
		for (const auto &y: ones) {
			if (twos.size()) twos.push_back(y[0]); // then we actually neeed this shit
			for (ll i = 0; i + 1 < ll(y.size()); ++i) b[y[i]][y[i+1]] = b[y[i+1]][y[i]] = 1;
		}
		// cout << "YA " << cur.twos.size() << endl;
		if (twos.size() != 0 and twos.size() < 3) return false; // cant have a cycle with less than 3 nodes bruh
		F(i, 0, twos.size()) {
			ll nidx = (i+1)%twos.size();
			b[twos[i]][twos[nidx]] = b[twos[nidx]][twos[i]] = 1;
		}
	}
	return 1;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();

	for (auto &x: p) for (auto y: x) if (y==3) return 0;
	F(i, 0, n) {
		dsu[i] = i;
		st[i] = {i};
	}

	F(i, 0, n) if (!vis[i]) {
		comp.clear();
		dfs(i, p);
		if (comp.size() == 1) continue; // empty live my life yo
		info cur;

		for (auto idx: comp) {
			ll ign = 0;
			for (auto x: comp) if (x-idx) {
				if (!p[idx][x]) return false; // everything within component is connected
				if (p[idx][x] == 1) {
					ll u = find(idx), v = find(x);
					if (u-v) {	
						if (st[u].size() < st[v].size()) swap(u, v);
						dsu[v] = u;
						st[u].insert(st[u].end(), st[v].begin(), st[v].end());
					}
				} else ign++;
			}
			if (ign + 1 == ll(comp.size())) cur.twos.push_back(idx); // all twos
		}

		set<ll> ivis;
		for (auto idx: comp) ivis.insert(find(idx));
		for (auto idx: ivis) {
			for (auto y: st[idx]) for (auto z: st[idx]) if (p[y][z] != 1) return false;
			cur.ones.push_back(st[idx]);
		}

		glob.push_back(cur);
	}	

	std::vector<std::vector<int>> answer;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}
	if (!my_build(answer)) return false;

	build(answer);
	return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22240 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1136 KB Output is correct
13 Correct 158 ms 22164 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 72 ms 8240 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 5888 KB Output is correct
21 Correct 157 ms 22052 KB Output is correct
22 Correct 150 ms 22084 KB Output is correct
23 Correct 159 ms 22100 KB Output is correct
24 Correct 151 ms 22052 KB Output is correct
25 Correct 61 ms 8276 KB Output is correct
26 Correct 60 ms 10136 KB Output is correct
27 Correct 165 ms 24216 KB Output is correct
28 Correct 147 ms 24144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
4 Incorrect 1 ms 348 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 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 39 ms 5936 KB Output is correct
5 Correct 166 ms 22092 KB Output is correct
6 Correct 151 ms 22104 KB Output is correct
7 Correct 176 ms 22052 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 38 ms 5968 KB Output is correct
10 Correct 157 ms 22096 KB Output is correct
11 Correct 156 ms 22356 KB Output is correct
12 Correct 158 ms 22324 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 16 ms 3500 KB Answer gives possible 0 while actual possible 1
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22240 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1136 KB Output is correct
13 Correct 158 ms 22164 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 72 ms 8240 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 5888 KB Output is correct
21 Correct 157 ms 22052 KB Output is correct
22 Correct 150 ms 22084 KB Output is correct
23 Correct 159 ms 22100 KB Output is correct
24 Correct 151 ms 22052 KB Output is correct
25 Correct 61 ms 8276 KB Output is correct
26 Correct 60 ms 10136 KB Output is correct
27 Correct 165 ms 24216 KB Output is correct
28 Correct 147 ms 24144 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Incorrect 1 ms 348 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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1140 KB Output is correct
7 Correct 166 ms 22240 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1136 KB Output is correct
13 Correct 158 ms 22164 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 72 ms 8240 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 5888 KB Output is correct
21 Correct 157 ms 22052 KB Output is correct
22 Correct 150 ms 22084 KB Output is correct
23 Correct 159 ms 22100 KB Output is correct
24 Correct 151 ms 22052 KB Output is correct
25 Correct 61 ms 8276 KB Output is correct
26 Correct 60 ms 10136 KB Output is correct
27 Correct 165 ms 24216 KB Output is correct
28 Correct 147 ms 24144 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Incorrect 1 ms 348 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -