Submit | All submissions | Best solutions | Back to list |
EIHTP - The highest total point |
Given a rooted tree with each node has a “point” value. Find a path that has total points of all nodes in the path is highest.
Input
The first line contains two integer n and m which are the number of nodes in the tree and the root of the given tree. Nodes are numbered from 0 to n - 1 (0 ≤ m < n ≤ 105)
The second line contains n integers which are points of all nodes, respectively.
Each line in the next (n – 1) lines contains two integers a, b which represent an edge in the tree.
Output
An integer representing the highest total point.
Sample
Input |
Output |
5 0 3 2 4 1 5 0 1 0 2 1 3 1 4 |
10 |
Added by: | Ha Minh Ngoc |
Date: | 2020-06-15 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYPY3 PYTHON3 RUBY SQLITE SWIFT VB.NET |