A kingdom has villages connected by 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.
The first line contains an integer () indicating the number of villages. Each village is identified by a distinct integer from to .
The second line contains integers , where if village has a watchtower, and otherwise. At least two of these values are .
Each of the next lines contains two integers and ( and ), indicating that there is a two-way road between villages and . It is guaranteed that it is possible to travel between any two villages using the roads.
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.
5 1 0 1 0 1 5 4 4 3 3 2 2 1
2 2
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.
6 1 0 0 1 1 1 2 1 4 2 1 3 6 3 2 5
2 4
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.