Under construction

Still being built. Things may change

Great GDP

Time limit1sMemory limit512 MB

Summary
Given a vertex-weighted tree and a value and weight per node, find the connected subtree containing the root that maximizes total value divided by total weight.
Level

Hard8 of 10

Topics
Binary search, Greedy, DFS, Tree
Solved
No attempts yet

Problem

In your beloved homeland Treetopia, there is exactly one way of travelling between any pair of cities. In the loathful Cyclostan, on the other hand, there are exactly two ways of travelling between every pair of cities.

A delegation from Cyclostan is coming to visit Treetopia, and you realize that this is your big chance of persuading them to adopt the benefits of a tree-like society! Your friend Øyvind will decide on a travel plan for the Cyclostan delegation. In order to impress the delegation as much as possible, you persuade Øyvind to take them to parts of the country such that the GDP per capita is maximized across the visited cities. The trip can include visiting cities on several branches in the country, and it is not possible to travel through a city without visiting it.

The one and only airport in Treetopia is in the capital Treetopolis, and this is where the delegation from Cyclostan will arrive.

Input

The first line of input contains an integer n (1 ≤ n ≤ 100 000), the number of cities in Treetopia. Then follows a line with n non-negative integers c1, c2, . . . cn (0 ≤ ci ≤ 1 000 000 for each i ∈ {1, 2, . . . , n}), the GDP of each city. Then follows a line with n positive integers k1, k2, . . . , kn (1 ≤ ki ≤ 1 000 000 for each i ∈ {1, 2, . . . , n}), the population of each city in Treetopia. Then follows n − 1 lines, the jth of which with two distinct integers uj and vj (1 ≤ uj, vj ≤ n), indicating that there is a road between cities uj and vj. Treetopolis is city number 1.

Output

The highest possible GDP per capita of a connected region of Treetopia that contains Treetopolis. Any answer within an absolute or relative error of 10-6 will be accepted as a correct answer.

Examples1

  1. Example 1

    Input
    3
    3 10 40
    1 2 10
    1 2
    1 3
    
    Expected output
    4.33333333333