看什么看
最富裕
甜美的富裕
100分还要考树结构
什么凳西
老登, 我倒要看看你要干什么
(虽然是用Java写代码, 但我争取每段之前都来点C语言, in my heart)
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] wealth = new long[n + 1];
long[] family = new long[n + 1];
for (int i = 1; i <= n; i++) {
wealth[i] = sc.nextInt();
family[i] = wealth[i];
}
for (int i = 0; i < n - 1; i++) {
int fa = sc.nextInt();
int ch = sc.nextInt();
family[fa] += wealth[ch];
}
System.out.println(Arrays.stream(family).max().orElse(0));
}
}