Minimize Sum of Distances
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
[ABC348E] Minimize Sum of Distances
题目描述
给定一棵 个顶点的树,每个点有一个点权 。定义 表示 和 之间的简单路径的边数(即距离),定义 $\displaystyle\ f(x)\ =\ \sum_{i=1}^{N}\ (C_i\ \times\ d(x,\ i))$ ,求 。
输入格式
第一行一个整数 ,接下来 行每行两个整数 表示树边,最后一行 个整数 表示点权。
输出格式
一个整数表示答案。
输入输出样例 #1
输入 #1
4
1 2
1 3
2 4
1 1 1 2
输出 #1
5
输入输出样例 #2
输入 #2
2
2 1
1 1000000000
输出 #2
1
输入输出样例 #3
输入 #3
7
7 3
2 5
2 4
3 1
3 6
2 1
2 7 6 9 3 4 6
输出 #3
56
说明/提示
数据范围
20250311集训
- Status
- Done
- Rule
- IOI
- Problem
- 7
- Start at
- 2025-3-11 19:30
- End at
- 2025-3-11 21:30
- Duration
- 2 hour(s)
- Host
- Partic.
- 9