L. Lookout Towers
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

A kingdom has $$$N$$$ villages connected by $$$N-1$$$ two-way roads, so that it is possible to travel between any two villages using the roads. The distance between two villages is the minimum number of roads needed to travel from one village to the other.

Some villages have a watchtower, and there are at least two watchtowers in the kingdom. The king wants to know how close the two nearest watchtowers are, and how many pairs of watchtowers are that close.

Input

The first line contains an integer $$$N$$$ ($$$2 \leq N \leq 2 \times 10^{5}$$$) indicating the number of villages. Each village is identified by a distinct integer from $$$1$$$ to $$$N$$$.

The second line contains $$$N$$$ integers $$${W_1}, {W_2}, \ldots, {W_N}$$$, where $$$W_i=1$$$ if village $$$i$$$ has a watchtower, and $$$W_i=0$$$ otherwise. At least two of these values are $$$1$$$.

Each of the next $$$N-1$$$ lines contains two integers $$$U$$$ and $$$V$$$ ($$$1 \leq U,V \leq N$$$ and $$$U \neq V$$$), indicating that there is a two-way road between villages $$$U$$$ and $$$V$$$. It is guaranteed that it is possible to travel between any two villages using the roads.

Output

Output a single line with two integers: the minimum distance between two different watchtowers, followed by the number of unordered pairs of watchtowers at that distance.

Examples
Input
5
1 0 1 0 1
5 4
4 3
3 2
2 1
Output
2 2
Input
6
1 0 0 1 1 1
2 1
4 2
1 3
6 3
2 5
Output
2 4
Note

Explanation for example 1

In this sample we have $$$N=5$$$ villages connected in a line, with watchtowers at both ends and in the middle (1–2–3–4–5). The minimum distance is $$$2$$$, with pairs $$$\{1,3\}$$$ and $$$\{3,5\}$$$ at that distance.

Explanation for example 2

Now we have $$$N=6$$$ villages, with watchtowers at villages $$$1$$$, $$$4$$$, $$$5$$$ and $$$6$$$. The pairs $$$\{1,4\}$$$, $$$\{1,5\}$$$, $$$\{1,6\}$$$ and $$$\{4,5\}$$$ are all at distance $$$2$$$. No other pair is at that distance or closer.