UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213810#582. t1xuewentao038ms6840kbC++111.1kb2024-11-13 20:14:272024-11-13 23:05:21

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 10;

int a[maxn];

int fa[maxn];
vector<int> G[maxn];

int r[maxn];

struct Point{
	int v, w;
};

bool operator > (const Point &a, const Point &b) {
	return a.w > b.w;
}

priority_queue<Point, vector<Point>, greater<Point> > que[maxn];

int n;

void init(int u) {
	r[u] = a[u];
	for (int v: G[u]) {
		init(v);
		r[u] = min(r[u], r[v]);
		que[u].push({v, r[v]});
	}
}

int vis[maxn];

int dfs(int u) {
	if (que[u].size() == 0) {
		vis[u] = 1;
		return u;
	}
	
	int res = dfs(que[u].top().v);
	
	if (vis[que[u].top().v]) {
		que[u].pop();
	} else {
		auto tmp = que[u].top();
		que[u].pop();
		que[u].push({tmp.v, min(a[tmp.v], tmp.w)});
	}
	
	return res;
}

int main() {
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> fa[i];
		G[fa[i]].push_back(i);
	}
	
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	
	init(1);
	
//	for (int i = 1; i <= n; i++) {
//		cout << i << " " << que[i].size() << endl;
//	}
	
	for (int i = 1; i <= n; i++) {
		cout << dfs(1) << " \n"[i==n];
	}
	
}

/*

4
1 2 2
1 3 2 4

*/

详细

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

Test #1:

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

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: 6ms
memory: 6748kb

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: 6ms
memory: 6740kb

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: 13ms
memory: 6840kb

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: 6ms
memory: 6832kb

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: 7ms
memory: 6836kb

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:

73271 97790 79288 53984 60747 97468 53394 52028 86145 66044 83125 79189 71343 78642 64397 71791 5494...

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:

96945 83722 81955 71333 78638 95923 70797 76976 94895 52218 95509 93397 66024 90339 80771 61576 6878...

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:

86618 75549 81311 81012 97035 72207 92094 68436 74897 70334 75944 68358 79221 66365 59063 84678 5914...

result: