QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323254 | #8215. Isomorphic Delight | karuna | WA | 7ms | 15640kb | C++20 | 2.7kb | 2024-02-09 01:30:56 | 2024-02-09 01:30:57 |
Judging History
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 = 7, p = 0, s = 0;
vector<pair<int, int>> V;
while (s != n) {
if (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';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 15560kb
input:
1
output:
YES 0
result:
ok Everything ok
Test #2:
score: 0
Accepted
time: 3ms
memory: 15392kb
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: 4ms
memory: 15568kb
input:
4
output:
NO
result:
ok Everything ok
Test #4:
score: 0
Accepted
time: 4ms
memory: 15536kb
input:
2
output:
NO
result:
ok Everything ok
Test #5:
score: 0
Accepted
time: 3ms
memory: 15640kb
input:
3
output:
NO
result:
ok Everything ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 15408kb
input:
5
output:
NO
result:
ok Everything ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 15588kb
input:
7
output:
YES 6 1 2 1 3 1 6 3 4 4 5 6 7
result:
ok Everything ok
Test #8:
score: -100
Wrong Answer
time: 7ms
memory: 15364kb
input:
8
output:
YES 7 1 2 1 3 1 6 3 4 4 5 6 7 6 8
result:
wrong answer contestant's solution is worse (more edges) than jury's