Universal Cup Judging System

Universal Cup

시간 제한: 4.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓
통계

정점 $1$이 루트인 $n$개의 정점으로 이루어진 트리를 생각해 봅시다. 트리의 각 정점 $i$는 가중치 $p_i$를 가지며, $p_1, p_2, \dots, p_n$은 순열을 이룹니다.

$L_{u,v}$를 정점 $u$에서 정점 $v$까지의 단순 경로(양 끝점 $u$와 $v$ 포함) 위에 있는 정점들의 최대 가중치라고 합시다. $\operatorname{subtree}(i)$를 정점 $i$의 서브트리를 이루는 정점들의 집합이라고 합시다. $S_i = \{u \mid u \in \operatorname{subtree}(i) \land L_{u,i} \le p_i\}$로 정의하는데, 이는 $i$에서 출발하여 자식 정점으로만 이동하면서 가중치가 $p_i$ 이하인 정점들만 거쳐 도달할 수 있는 정점들의 집합입니다. $f_i = |S_i|$를 이 정점 집합의 크기라고 합시다.

정점의 가치를 $q_{f_i}$로 정의하며, 여기서 $q$는 주어진 수열 $q_1, q_2, \dots, q_n$입니다.

이제 각 순서쌍 $(i, j)$에 대해, $p_i = j$를 만족하는 모든 가중치 배치에서 정점 $i$의 가치의 합을 구하고자 합니다. 답이 매우 클 수 있으므로, 결과를 $10^9 + 7$로 나눈 나머지를 출력하세요.

입력

첫 번째 줄에는 트리의 정점 개수를 나타내는 정수 $n$ ($1 \le n \le 700$)이 주어집니다.

다음 줄에는 $q_1, q_2, \dots, q_n$ ($0 \le q_i < 10^9 + 7$)을 나타내는 $n$개의 정수가 주어집니다.

다음 $n - 1$개의 줄에는 각각 트리의 간선을 나타내는 두 정수 $u, v$가 주어집니다.

출력

각각 $n$개의 정수를 포함하는 $n$개의 줄을 출력합니다. $i$번째 줄의 $j$번째 정수는 해당하는 답을 $10^9 + 7$로 나눈 나머지를 나타냅니다.

예제

입력 1

3
1 1 2
1 2
2 3

출력 1

2 2 4
2 2 2
2 2 2

입력 2

4
1 2 3 4
1 2
2 3
1 4

출력 2

6 10 16 24
6 8 10 12
6 6 6 6
6 6 6 6

입력 3

7
3 7 2 4 1 8 9
1 2
1 3
2 4
4 5
3 6
4 7

출력 3

2160 3120 3168 2952 2160 3720 6480
2160 2640 2640 2412 2208 2280 2880
2160 2640 3120 3600 4080 4560 5040
2160 3120 3648 3744 3408 2640 1440
2160 2160 2160 2160 2160 2160 2160
2160 2160 2160 2160 2160 2160 2160
2160 2160 2160 2160 2160 2160 2160

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1702EditorialOpenAnother SolutionMilmonView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.