QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323255#8215. Isomorphic DelightkarunaWA 10ms15608kbC++202.7kb2024-02-09 01:31:362024-02-09 01:31:37

Judging History

你现在查看的是最新测评结果

  • [2024-02-09 01:31:37]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:15608kb
  • [2024-02-09 01:31:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int SZ = 21;

vector<vector<pair<int, int>>> R[SZ + 1]; // rooted trees
vector<vector<pair<int, int>>> T[SZ + 1]; // non-rooted

vector<pair<int, int>> E;

void f(int n, int s, int m, int j, bool h) {
	if (s == n) {
		if (!h) R[n].push_back(E);
		else T[n].push_back(E);
		return;
	}
	assert(n - s >= m);
	if (n - s < 2 * m) {
		if (m != n - s) j = 0;
		m = n - s;
	}
	if (h && m >= (n + 1) / 2) return;

	// don't use m
	if (s + m + 1 <= n)
		f(n, s, m + 1, 0, h);

	// use m
	for (int k = j; k < R[m].size(); k++) {
		E.push_back({ 1, s + 1 });
		for (auto [u, v] : R[m][k]) {
			E.push_back({ s + u, s + v });
		}

		f(n, s + m, m, k + 1, h);

		for (int l = 0; l < m; l++) E.pop_back();
	}
}

void generate(int n) {
	if (n <= 10) f(n, 1, 1, 0, false);
	f(n, 1, 1, 0, true);
	if (n % 2 == 0) {
		for (int i = 0; i < R[n / 2].size(); i++) for (int j = 0; j < i; j++) {
			vector<pair<int, int>> E;
			E.push_back({ 1, n / 2 + 1 });
			for (auto [u, v] : R[n / 2][i]) E.push_back({ u, v });
			for (auto [u, v] : R[n / 2][j]) E.push_back({ n / 2 + u, n / 2 + v });
			T[n].push_back(E);
		}
	}
}
int main() {
	for (int n = 1; n <= SZ; n++) {
		generate(n);
	}

	int n;
	cin >> n;

	if (n == 1) {
		cout << "YES\n";
		cout << 0 << '\n';
	}
	else if (n <= 5) {
		cout << "NO\n";
	}
	else if (n == 6) {
		cout << "YES\n";
		cout << 6 << '\n';
		cout << "1 2\n";
		cout << "2 3\n";
		cout << "3 1\n";
		cout << "1 4\n";
		cout << "2 5\n";
		cout << "5 6\n";
	}
	else {
		int m = 1, p = 0, s = 0;
		vector<pair<int, int>> V;
		while (s != n) {
			while (p == T[m].size()) {
				++m;
				p = 0;
			}
			bool f = false;
			if (s + m + (p + 1 == T[m].size() ? m + 1 : m) > n) {
				f = true;
			}
			if (!f) {
				for (auto [u, v] : T[m][p]) {
					V.push_back({ s + u, s + v });
				}
				++p;
				s += m;
			}
			else {
				int k = n - s;
				if (k % 2 == 0) {
					V.push_back({ s + 1, s + 2 });
					V.push_back({ s + 1, s + 3 });
					V.push_back({ s + 1, s + k / 2 + 2 });
					for (int i = 0; i < k / 2 - 2; i++) V.push_back({ s + 3 + i, s + 4 + i });
					for (int i = 0; i < k / 2 - 3; i++) V.push_back({ s + k / 2 + 2 + i, s + k / 2 + 3 + i });
					V.push_back({ n - 2, n });
				}
				else {
					V.push_back({ s + 1, s + 2 });
					V.push_back({ s + 1, s + 3 });
					V.push_back({ s + 1, s + k / 2 + 3 });
					for (int i = 0; i < k / 2 - 1; i++) V.push_back({ s + 3 + i, s + 4 + i });
					for (int i = 0; i < k / 2 - 2; i++) V.push_back({ s + k / 2 + 3 + i, s + k / 2 + 4 + i });
				}
				break;
			}
		}
		cout << "YES\n";
		cout << V.size() << '\n';
		for (auto [u, v] : V) {
			cout << u << ' ' << v << '\n';
		}
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 15508kb

input:

1

output:

YES
0

result:

ok Everything ok

Test #2:

score: 0
Accepted
time: 6ms
memory: 15488kb

input:

6

output:

YES
6
1 2
2 3
3 1
1 4
2 5
5 6

result:

ok Everything ok

Test #3:

score: 0
Accepted
time: 6ms
memory: 15496kb

input:

4

output:

NO

result:

ok Everything ok

Test #4:

score: 0
Accepted
time: 5ms
memory: 15608kb

input:

2

output:

NO

result:

ok Everything ok

Test #5:

score: 0
Accepted
time: 6ms
memory: 15356kb

input:

3

output:

NO

result:

ok Everything ok

Test #6:

score: 0
Accepted
time: 10ms
memory: 15524kb

input:

5

output:

NO

result:

ok Everything ok

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 15492kb

input:

7

output:

YES
5
2 3
2 4
2 6
4 5
5 7

result:

wrong answer Not asymmetric