UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213833#582. t1honghaojin012ms4488kbC++11904b2024-11-13 21:09:202024-11-13 23:07:49

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::min;
using ll=long long;
const int N=1e5+10,inf=2e9;
int hd[N],to[N],nt[N],cnt;
#define add(u,v)\
	to[++cnt]=v,nt[cnt]=hd[u],hd[u]=cnt

int fa[N],a[N],r[N];
struct Compare{
	bool operator()(int x,int y){
		return r[x]>r[y];
	}
};
std::priority_queue<int,std::vector<int>,Compare>q[N];
void init(int u){
	for(int e=hd[u];e;e=nt[e]){
		int v=to[e];
		init(v),q[u].push(v);
	}
	r[u]=!q[u].empty()&&r[q[u].top()]<a[u]?r[q[u].top()]:a[u];
}
int dfs(int u){
	if(q[u].empty())return u;
	int v=q[u].top();q[u].pop();
	int res=dfs(v);
	if(res!=v)q[u].push(v);
	return res;
}
int main(){
	std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	for(int i=2;i<=n;++i)cin>>fa[i],add(fa[i],i);
	for(int i=1;i<=n;++i)cin>>a[i];
	init(1);
	for(int i=1;i<=n;++i)
		cout<<dfs(1)<<' ';
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4416kb

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 61 64 100 53 73 97 50 49 48 47 63 46 45 44 51 43 78 42 41 40 62 39 38 71 93 37 36 35 83 34 33 88 ...

result:

wrong answer 2nd numbers differ - expected: '75', found: '61'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 4412kb

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 50 49 81 69 48 74 47 46 77 45 83 44 73 43 88 71 42 66 100 63 51 41 62 40 39 38 92 37 36 ...

result:

wrong answer 5th numbers differ - expected: '88', found: '50'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 4412kb

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 71 60 96 50 49 87 62 48 47 46 45 44 43 42 41 40 39 86 38 37 78 36 79 35 92 67 56 34 52 33 32 31 5...

result:

wrong answer 2nd numbers differ - expected: '100', found: '71'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 4488kb

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 764 559 958 922 685 918 793 760 840 659 637 718 535 722 508 646 576 657 597 582 987 734 986 723 ...

result:

wrong answer 2nd numbers differ - expected: '630', found: '764'

Test #5:

score: 0
Wrong Answer
time: 5ms
memory: 4484kb

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 836 916 659 525 592 528 500 499 622 892 498 843 497 496 797 495 518 494 918 904 646 ...

result:

wrong answer 5th numbers differ - expected: '760', found: '836'

Test #6:

score: 0
Wrong Answer
time: 5ms
memory: 4488kb

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 613 677 573 774 880 521 500 499 498 497 496 495 494 493 554 492 491 565 720 561 490 942 630 489 ...

result:

wrong answer 2nd numbers differ - expected: '829', found: '613'

Test #7:

score: 0
Time Limit Exceeded

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:


result:


Test #8:

score: 0
Time Limit Exceeded

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:


result:


Test #9:

score: 0
Time Limit Exceeded

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:


result:


Test #10:

score: 0
Time Limit Exceeded

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:


result: