Submission #837104

# Submission time Handle Problem Language Result Execution time Memory
837104 2023-08-24T23:45:19 Z JustAmethyst Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1000 ms 2097152 KB
#include "supertrees.h"
#include <bits/stdc++.h>
#define sz(x) (int)(x.size())
using namespace std;

vector<int> a, b;
vector<vector<int>> answer;
vector<int> done;

// void build(vector<vector<int>> ans) {
// 	for (auto x : ans) {
// 		for (auto y : x) {
// 			cout << y << " ";
// 		}
// 		cout << "\n";
// 	}
// }

bool check1(int x, int n, vector<vector<int>> p) {
	int c = 0;
	for (int i = 0; i < n; ++i) {
		if (p[x][i] == 1) {
			if (done[i] != 1) return 0;
			++c;
		}
	}
	return (c == sz(a));
}

bool check2(int x, int n, vector<vector<int>> p) {
	int c = 1;
	for (int i = 0; i < n; ++i) {
		if (i != x) {
			if (p[x][i] == 2) {
				// if (done[i] != 2) {
				// 	cout << "here - " << x << " " << i << "\n";
				// 	return 0;
				// }
				++c;
			}
		}
	}
	// cout << "c = " << c << "\n";
	return (c == (sz(a) + sz(b)));
}

void place(int x, int n, vector<vector<int>> p) {
	bool y = 0;
	int z = 0;
	done[x] = 3;
	for (int i = 0; i < n; ++i) {
		if (i != x && p[x][i]) {
			if (p[x][i] == 1) {
				// cout << x << " " << i << "\n";
				y = 1;
			}

			if (done[i] == 0) place(i, n, p);
		}

		if (p[x][i] == 0) ++z;
	}

	if (z == n-1) return;

	if (y) {
		a.push_back(x);
		done[x] = 1;
	}
	else {
		b.push_back(x);
		done[x] = 2;
	}
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	for (int i = 0; i < n; i++) {
		done.push_back(0);
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
	}

	for (int i = 0; i < n; ++i) {
		if (done[i] == 0) place(i, n, p);
		else continue;

		if (done[i] == 3) continue;
		if (done[i] == 1) {
			if (!check1(i, n, p)) return 0;
		}
		else {
			if (!check2(i, n, p)) return 0;
		}

	
		if (sz(b) <= 2 && sz(a) == 0) {
			// cout << 2 << "\n";
			return 0;
		}

		for (int j = 1; j < sz(a); ++j) {
			answer[0][j] = 1;
			answer[j][0] = 1;
		}
		if (sz(a) && sz(b)) {
			answer[a[0]][b[0]] = 1;
			answer[b[0]][a[0]] = 1;

			answer[a[0]][b[sz(b)-1]] = 1;
			answer[b[sz(b)-1]][a[0]] = 1;
		}
		else if (sz(b)) {
			answer[b[0]][b[sz(b)-1]] = 1;
			answer[b[sz(b)-1]][b[0]] = 1;
		}
		for (int j = 0; j < sz(b)-1; ++j) {
			answer[b[j]][b[j+1]] = 1;
			answer[b[j+1]][b[j]] = 1;
		}

		a.clear();
		b.clear();

		// for (auto x : done) cout << x << " ";
		// for (auto x : a) cout << x << " ";
		// cout << "\n";
		// for (auto x : b) cout << x << " ";
		// cout << "\n";
	}

	// for (int i = 1; i < n; ++i) {
	// 	answer[0][i] = 1;
	// 	answer[i][0] = 1;
	// }
	build(answer);
	return 1;
}

// int main() {
// 	int n, a;
// 	cin >> n;
// 	vector<vector<int>> p;
// 	for (int i = 0; i < n; ++i) {
// 		p.push_back({});
// 		for (int j = 0; j < n; ++j) {
// 			cin >> a;
// 			p[i].push_back(a);
// 		}
// 	}
// 	construct(p);
// }
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 20 ms 33768 KB Output is correct
7 Execution timed out 1079 ms 2097152 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 20 ms 33768 KB Output is correct
7 Execution timed out 1079 ms 2097152 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 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 256 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 10 ms 1140 KB Output is correct
9 Execution timed out 1093 ms 21800 KB Time limit exceeded
10 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 Incorrect 0 ms 212 KB Too many ways to get from 0 to 1, should be 0 found no less than 1
4 Halted 0 ms 0 KB -
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 20 ms 33768 KB Output is correct
7 Execution timed out 1079 ms 2097152 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 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 1 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 20 ms 33768 KB Output is correct
7 Execution timed out 1079 ms 2097152 KB Time limit exceeded
8 Halted 0 ms 0 KB -