ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213838 | #582. t1 | nodgd | 100 | 176ms | 5620kb | C++11 | 835b | 2024-11-13 21:27:48 | 2024-11-13 23:08:25 |
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 5;
int N, a[MAX_N], ai[MAX_N];
int fath[MAX_N], anc[MAX_N];
vector<int> son[MAX_N];
int get_anc(int x) {
return anc[x] == x ? x : anc[x] = get_anc(anc[x]);
}
void dfs(int u) {
reverse(son[u].begin(), son[u].end());
for (int v: son[u]) {
dfs(v);
}
printf("%d%c", u, u > 1 ? ' ' : '\n');
}
int main() {
scanf("%d", &N);
for (int i = 2; i <= N; i ++) {
scanf("%d", &fath[i]);
}
for (int i = 1; i <= N; i ++) {
scanf("%d", &a[i]);
ai[i] = i;
anc[i] = i;
}
sort(ai + 1, ai + 1 + N, [] (int i, int j) {
return a[i] < a[j];
});
for (int i = N; i >= 1; i --) {
int x = ai[i];
if (x == 1) continue;
int y = get_anc(fath[x]);
son[y].push_back(x);
anc[x] = fath[x];
}
dfs(1);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 3608kb
input:
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...
output:
52 75 61 96 94 85 99 65 92 64 100 53 79 67 84 89 69 62 88 58 87 68 51 76 56 70 74 55 91 72 59 82 71 ...
result:
ok 100 numbers
Test #2:
score: 10
Accepted
time: 1ms
memory: 3604kb
input:
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...
output:
97 98 56 64 88 71 85 54 94 81 69 74 77 82 66 76 100 95 78 57 93 86 80 83 63 90 68 99 53 52 73 91 96 ...
result:
ok 100 numbers
Test #3:
score: 10
Accepted
time: 0ms
memory: 3608kb
input:
100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...
output:
68 100 83 82 66 57 73 90 74 89 92 84 78 52 99 65 75 54 71 87 85 77 61 93 72 63 64 58 60 69 91 96 67 ...
result:
ok 100 numbers
Test #4:
score: 10
Accepted
time: 0ms
memory: 3620kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
output:
720 630 795 982 858 778 764 843 958 636 655 718 999 640 819 553 685 815 801 611 580 660 848 722 508 ...
result:
ok 1000 numbers
Test #5:
score: 10
Accepted
time: 1ms
memory: 3624kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
output:
993 967 945 661 760 801 836 832 798 725 609 708 916 659 785 955 912 802 778 739 850 529 680 664 847 ...
result:
ok 1000 numbers
Test #6:
score: 10
Accepted
time: 1ms
memory: 3620kb
input:
1000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35...
output:
865 829 713 826 804 598 835 729 919 613 859 604 586 677 926 808 871 883 512 573 946 688 540 980 501 ...
result:
ok 1000 numbers
Test #7:
score: 10
Accepted
time: 47ms
memory: 5620kb
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...
output:
60966 84526 92926 81979 52715 89039 62563 60694 55151 70404 50693 82115 87107 88733 92525 69003 5623...
result:
ok 100000 numbers
Test #8:
score: 10
Accepted
time: 43ms
memory: 5620kb
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...
output:
73271 97790 79288 53984 60747 85301 62325 94837 68122 92850 54755 72761 86308 93120 85924 58122 5785...
result:
ok 100000 numbers
Test #9:
score: 10
Accepted
time: 41ms
memory: 5620kb
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...
output:
96945 71333 97384 73952 87860 78638 54641 53438 84679 65487 87180 73489 72817 69821 95923 70797 7798...
result:
ok 100000 numbers
Test #10:
score: 10
Accepted
time: 42ms
memory: 5620kb
input:
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...
output:
86618 75549 54929 84432 89351 73329 74867 54756 55393 96686 62390 82968 79815 69008 65957 58416 6517...
result:
ok 100000 numbers
Extra Test:
score: 0
Extra Test Passed