Logo
(追記) (追記ここまで)

14446번 - Promotion Counting 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB92339230447.205%

문제

The cows have once again tried to form a startup company, failing to remember from past experience that cows make terrible managers!

The cows, conveniently numbered 1…N (1 ≤ N ≤ 100,000), organize the company as a tree, with cow 1 as the president (the root of the tree). Each cow except the president has a single manager (its "parent" in the tree). Each cow i has a distinct proficiency rating, p(i), which describes how good she is at her job. If cow ii is an ancestor (e.g., a manager of a manager of a manager) of cow j, then we say j is a subordinate of i.

Unfortunately, the cows find that it is often the case that a manager has less proficiency than several of her subordinates, in which case the manager should consider promoting some of her subordinates. Your task is to help the cows figure out when this is happening. For each cow i in the company, please count the number of subordinates j where p(j)>p(i).

입력

The first line of input contains N.

The next NN lines of input contain the proficiency ratings p(1)…p(N) for the cows. Each is a distinct integer in the range 1…1,000,000,000.

The next N−1 lines describe the manager (parent) for cows 2…N. Recall that cow 1 has no manager, being the president.

출력

Please print N lines of output. The iith line of output should tell the number of subordinates of cow i with higher proficiency than cow i.

제한

예제 입력 1

5
804289384
846930887
681692778
714636916
957747794
1
1
2
3

예제 출력 1

2
0
1
0
0

힌트

출처

Olympiad > USA Computing Olympiad > 2016-2017 Season > USACO 2017 January Contest > Platinum 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /