QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 128 MB 總分: 100 可 Hack ✓

#16096. Joint Weights

统计

An undirected connected graph $G$ has $n$ vertices and $n-1$ edges. The vertices are numbered from $1$ to $n$, and the weight of vertex $i$ is $W_i$. Each edge has a length of $1$. The distance between two vertices $(u, v)$ in the graph is defined as the shortest distance between them. For any pair of vertices $(u, v)$ in graph $G$, if their distance is $2$, they produce a joint weight of $W_u \times W_v$.

Find the maximum joint weight among all ordered pairs of vertices in graph $G$ that produce a joint weight, and the sum of all such joint weights.

Input

The first line contains an integer $n$.

The next $n-1$ lines each contain two space-separated positive integers $u$ and $v$, representing an edge between vertex $u$ and vertex $v$.

The last line contains $n$ positive integers, separated by spaces, where the $i$-th integer represents the weight $W_i$ of vertex $i$ in graph $G$.

Output

Output a single line containing two integers separated by a space: the maximum joint weight and the sum of all joint weights in graph $G$. Since the sum of all joint weights may be very large, output it modulo $10007$. It is guaranteed that there exists at least one ordered pair of vertices that produces a joint weight.

Examples

Input 1

5
1 2
2 3
3 4
4 5
1 5 2 3 10

Output 1

20 74

Note

The graph for this example is shown above. The ordered pairs with a distance of $2$ are $(1,3), (2,4), (3,1), (3,5), (4,2), (5,3)$. Their joint weights are $2, 15, 2, 20, 15, 20$, respectively. The maximum is $20$, and the total sum is $74$.

Constraints

For 30% of the data, $1 < n \leq 100$.

For 60% of the data, $1 < n \leq 2000$.

For 100% of the data, $1 < n \leq 200000, 0 < W_i \leq 10000$.

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.