Hierarchical employee structure
Its annual offsite time at the Air Conditioning Machinery (ACM) Company. All the employees are excited about it. The company has a hierarchical employee structure with one CEO who is at the topmost level of the hierarchy. Every other employee reports to a manager who belongs to the hierarchy level just above his level. Associated with each employee e is a fun index F(e) which denotes how comfortable everyone is with the employee.
Alice is planning the travel groups. An employee's manager will of course hate it if one of his subordinates is invited to the offsite and he is not. So she must select a group such that: 1. The CEO is selected (of course) 2. For each other employee who is present, his manager is also present in the group.
She wants to know the maximum average fun index she can have for any feasible group. Can you find it for her?
The CEO is always the employee numbered 1. The average fun index of a group is the arithmetic mean of all the fun indices of the employees of the group.
Input
First line of the input contains an integer t, the number of test cases. Each test case begins with an integer N, the number of employees. The next line contains N space separated integers where the i-th number denotes the fun index of employee i, F(i). The next N-1 lines contains two space separated integers a b which means that b reports to a. (1 ≤ a, b ≤ N).
It is known that 1 ≤ t ≤ 20, 1 ≤ N ≤ 50000, 0 ≤ F(i) ≤ 10000.
Output
For each test case output in the separate line the maximum average fun index rounded to 3 decimal places.