fork download
  1. package trees;
  2.  
  3. import java.util.*;
  4.  
  5. public class vmWareOAProbelm_4 {
  6. public static long solution(int node, ArrayList<Integer>[] tree, int[] b, int visited[], int parent[], long[] dp) {
  7. visited[node] = 1;
  8. long maxi = 0;
  9. for (int child : tree[node]) {
  10. if (child != parent[node]) {
  11. parent[child] = node;
  12. long value = solution(child, tree, b, visited, parent, dp);
  13. maxi = Math.max(maxi, value);
  14. }
  15. }
  16. dp[node] = b[node] + maxi;
  17. return dp[node];
  18. }
  19.  
  20. public static void main(String[] args) {
  21. Scanner scn = new Scanner(System.in);
  22. int n = scn.nextInt();
  23. ArrayList<Integer>[] tree = new ArrayList[n + 1];
  24. for (int i = 0; i <= n; i++) {
  25. tree[i] = new ArrayList<>();
  26. }
  27. int[] b = new int[n + 1];
  28. for (int i = 1; i < n; i++) {
  29. int x = scn.nextInt();
  30. int y = scn.nextInt();
  31. tree[x].add(y);
  32. tree[y].add(x);
  33. }
  34. for (int i = 1; i <= n; i++) {
  35. b[i] = scn.nextInt();
  36. }
  37. int visited[] = new int[n + 1];
  38. int parent[] = new int[n + 1];
  39. long dp[] = new long[n + 1];
  40. solution(1, tree, b, visited, parent, dp);
  41. long ans = Long.MIN_VALUE;
  42. for (int i = 1; i <= n; i++) {
  43. ans = Math.max(ans, dp[i]);
  44. }
  45. System.out.println(ans);
  46. }
  47. }
  48.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:5: error: class vmWareOAProbelm_4 is public, should be declared in a file named vmWareOAProbelm_4.java
public class vmWareOAProbelm_4 {
       ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
stdout
Standard output is empty