QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350462 | #8215. Isomorphic Delight | ucup-team1198# | AC ✓ | 131ms | 69536kb | C++20 | 3.6kb | 2024-03-10 18:59:17 | 2024-03-10 18:59:18 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
const int MAXN = 2e6;
vector<int> g[MAXN];
int cur_id = 0;
int nn() {
return cur_id++;
}
vector<int> roots;
vector<int> sizes;
vector<int> path;
int rec_bf(int id, int start, int n, vector<int>& to, vector<int>& sz) {
if (n == 0) {
int v = nn();
g[v] = path;
to.push_back(v);
sz.push_back(start);
return 1;
}
if (id >= roots.size() || sizes[id] > n) return 0;
int cnt = 0;
path.push_back(roots[id]);
cnt += rec_bf(id + 1, start, n - sizes[id], to, sz);
path.pop_back();
cnt += rec_bf(id + 1, start, n, to, sz);
return cnt;
}
vector<array<int, 2>> ans;
int id = 0;
vector<int> ansg[MAXN];
int build(int v) {
int cur = id++;
for (int u : g[v]) {
int res = build(u);
ans.push_back({cur, res});
ansg[cur].push_back(res);
ansg[res].push_back(cur);
}
return cur;
}
vector<int> vert;
void dfs(int v, int p = -1) {
vert.push_back(v);
for (int u : ansg[v]) {
if (u == p) continue;
dfs(u, v);
}
}
int len(int v, int p = -1) {
if (ansg[v].size() >= 3) return 0;
int bst = 100;
for (int u : ansg[v]) {
if (u == p) continue;
int res = len(u, v);
bst = min(bst, res + 1);
}
return bst;
}
int get_vert(int v) {
vert.clear();
dfs(v);
if (vert.size() == 1) return vert[0];
int val = -1, mx = -1;
for (int v : vert) {
if (ansg[v].size() > 1) continue;
int cur = len(v);
if (cur > val) {
val = cur;
mx = v;
}
}
return mx;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> gr, gsz;
int sum = 0;
for (int k = 1; sum < n; ++k) {
sum += k * rec_bf(0, k, k - 1, gr, gsz);
if (sum >= n) break;
if (k % 2 == 0) {
int l = roots.size();
rec_bf(0, k / 2, k / 2 - 1, roots, sizes);
int r = roots.size();
for (int i = l; i < r && sum < n; ++i) {
for (int j = l; j < i && sum < n; ++j) {
int v = nn();
g[v] = g[roots[i]];
g[v].push_back(roots[j]);
gr.push_back(v);
gsz.push_back(k);
sum += k;
}
}
}
}
if (n > 1 && n < 6) {
cout << "NO\n";
return 0;
}
if (n == 6) {
cout << "YES\n6\n";
cout << "1 2\n";
cout << "2 3\n";
cout << "1 3\n";
cout << "3 4\n";
cout << "2 5\n";
cout << "5 6\n";
return 0;
}
int last = -1;
for (int i = 0; i < (int)gr.size(); ++i) {
if (n < gsz[i]) break;
if (n == 7 && gsz[i] == 1) continue;
last = build(gr[i]);
n -= gsz[i];
}
int v = get_vert(last);
for (int i = 0; i < n; ++i) {
int u = id++;
ans.push_back({v, u});
v = u;
}
cout << "YES\n";
cout << ans.size() << "\n";
for (auto elem : ans) {
cout << elem[0] + 1 << " " << elem[1] + 1 << "\n";
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3564kb
input:
1
output:
YES 0
result:
ok Everything ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
6
output:
YES 6 1 2 2 3 1 3 3 4 2 5 5 6
result:
ok Everything ok
Test #3:
score: 0
Accepted
time: 4ms
memory: 3648kb
input:
4
output:
NO
result:
ok Everything ok
Test #4:
score: 0
Accepted
time: 4ms
memory: 3548kb
input:
2
output:
NO
result:
ok Everything ok
Test #5:
score: 0
Accepted
time: 4ms
memory: 3800kb
input:
3
output:
NO
result:
ok Everything ok
Test #6:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
5
output:
NO
result:
ok Everything ok
Test #7:
score: 0
Accepted
time: 4ms
memory: 3512kb
input:
7
output:
YES 6 1 2 3 4 1 3 6 7 5 6 1 5
result:
ok Everything ok
Test #8:
score: 0
Accepted
time: 4ms
memory: 3636kb
input:
8
output:
YES 6 2 3 4 5 2 4 7 8 6 7 2 6
result:
ok Everything ok
Test #9:
score: 0
Accepted
time: 4ms
memory: 3808kb
input:
9
output:
YES 7 2 3 4 5 2 4 7 8 6 7 2 6 8 9
result:
ok Everything ok
Test #10:
score: 0
Accepted
time: 2ms
memory: 3568kb
input:
10
output:
YES 8 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10
result:
ok Everything ok
Test #11:
score: 0
Accepted
time: 4ms
memory: 3596kb
input:
11
output:
YES 9 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10 10 11
result:
ok Everything ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
12
output:
YES 10 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10 10 11 11 12
result:
ok Everything ok
Test #13:
score: 0
Accepted
time: 4ms
memory: 3616kb
input:
13
output:
YES 11 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10 10 11 11 12 12 13
result:
ok Everything ok
Test #14:
score: 0
Accepted
time: 4ms
memory: 3652kb
input:
14
output:
YES 12 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10 10 11 11 12 12 13 13 14
result:
ok Everything ok
Test #15:
score: 0
Accepted
time: 4ms
memory: 3616kb
input:
15
output:
YES 13 2 3 4 5 2 4 7 8 6 7 2 6 8 9 9 10 10 11 11 12 12 13 13 14 14 15
result:
ok Everything ok
Test #16:
score: 0
Accepted
time: 4ms
memory: 3624kb
input:
16
output:
YES 13 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13
result:
ok Everything ok
Test #17:
score: 0
Accepted
time: 4ms
memory: 3556kb
input:
17
output:
YES 14 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 12 17
result:
ok Everything ok
Test #18:
score: 0
Accepted
time: 4ms
memory: 3572kb
input:
18
output:
YES 15 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 12 17 17 18
result:
ok Everything ok
Test #19:
score: 0
Accepted
time: 4ms
memory: 3848kb
input:
19
output:
YES 16 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 12 17 17 18 18 19
result:
ok Everything ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
598
output:
YES 544 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #21:
score: 0
Accepted
time: 4ms
memory: 3636kb
input:
245
output:
YES 221 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #22:
score: 0
Accepted
time: 4ms
memory: 3680kb
input:
793
output:
YES 724 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #23:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
133
output:
YES 119 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #24:
score: 0
Accepted
time: 4ms
memory: 3628kb
input:
681
output:
YES 620 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #25:
score: 0
Accepted
time: 5ms
memory: 3864kb
input:
922
output:
YES 843 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #26:
score: 0
Accepted
time: 4ms
memory: 3640kb
input:
876
output:
YES 800 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57 ...
result:
ok Everything ok
Test #27:
score: 0
Accepted
time: 5ms
memory: 4148kb
input:
7740
output:
YES 7191 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57...
result:
ok Everything ok
Test #28:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
2460
output:
YES 2268 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57...
result:
ok Everything ok
Test #29:
score: 0
Accepted
time: 5ms
memory: 4380kb
input:
7533
output:
YES 6998 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57...
result:
ok Everything ok
Test #30:
score: 0
Accepted
time: 2ms
memory: 4032kb
input:
5957
output:
YES 5527 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 57...
result:
ok Everything ok
Test #31:
score: 0
Accepted
time: 15ms
memory: 9288kb
input:
92651
output:
YES 87225 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 5...
result:
ok Everything ok
Test #32:
score: 0
Accepted
time: 10ms
memory: 7296kb
input:
58779
output:
YES 55235 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 5...
result:
ok Everything ok
Test #33:
score: 0
Accepted
time: 6ms
memory: 4576kb
input:
12203
output:
YES 11374 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 5...
result:
ok Everything ok
Test #34:
score: 0
Accepted
time: 13ms
memory: 7224kb
input:
55627
output:
YES 52258 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 5...
result:
ok Everything ok
Test #35:
score: 0
Accepted
time: 16ms
memory: 9728kb
input:
99051
output:
YES 93269 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 5...
result:
ok Everything ok
Test #36:
score: 0
Accepted
time: 120ms
memory: 59328kb
input:
811713
output:
YES 770513 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 ...
result:
ok Everything ok
Test #37:
score: 0
Accepted
time: 78ms
memory: 38792kb
input:
544133
output:
YES 515717 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 ...
result:
ok Everything ok
Test #38:
score: 0
Accepted
time: 46ms
memory: 21856kb
input:
276553
output:
YES 261516 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 ...
result:
ok Everything ok
Test #39:
score: 0
Accepted
time: 110ms
memory: 54456kb
input:
736904
output:
YES 699266 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 ...
result:
ok Everything ok
Test #40:
score: 0
Accepted
time: 131ms
memory: 69536kb
input:
1000000
output:
YES 949834 2 3 4 5 2 4 7 8 6 7 2 6 11 12 10 11 9 10 13 14 15 16 13 15 9 13 17 18 20 21 19 20 17 19 22 23 24 25 22 24 17 22 26 27 29 30 28 29 26 28 33 34 32 33 31 32 26 31 36 37 38 39 36 38 35 36 42 43 41 42 40 41 35 40 44 45 46 47 48 49 46 48 44 46 52 53 51 52 50 51 44 50 55 56 54 55 58 59 57 58 54 ...
result:
ok Everything ok
Extra Test:
score: 0
Extra Test Passed