DMOPC '21 Contest 1 P6 - Tree Jumping

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem types

Unfortunately, it turns out that a lot of the shows you've been watching this season haven't really lived up to their hype. To vent your frustration, you've decided to spend the weekend jumping in a tree instead.

The tree you're jumping in is rooted at node 1 with N nodes connected by N-1 edges, the i-th edge connecting nodes u_i and v_i with a length of l_i. Each node i has 2 values r_i and c_i.

You may jump from node a to node b if b is a descendant of a and r_a > c_b, with a danger factor of \dfrac{dist(a, b)}{r_a - c_b} where dist(a, b) is the length of the shortest path from a to b.

For each node i from 2 to N, find the minimum danger factor of a direct jump from some node to node i or determine that it is impossible to jump to this node.

Constraints

2 \le N \le 3 \times 10^5

1 \le r_i, c_i, l_i \le 10^9

1 \le u_i, v_i \le N

Subtask 1 [30%]

u_i = i and v_i = i+1 for all i.

Subtask 2 [70%]

No additional constraints.

Input Specification

The first line contains an integer N.

The second line contains N integers r_i (1 \le i \le N).

The third line contains N integers c_i (1 \le i \le N).

The next N-1 lines each contain 3 integers u_i, v_i, and l_i.

Output Specification

Output N-1 lines, the i-th line containing the minimum danger factor of a direct jump from some node to node i+1 or Unreachable if it is impossible to jump to this node. Your output will be considered correct if the absolute or relative error of each numerical value does not exceed 10^{-9}.

Sample Input

7
11 8 7 2 6 3 9
2 1 1 5 4 3 13
2 4 3
1 2 3
7 1 4
3 6 6
2 3 2
5 3 1

Sample Output

0.300000000000
0.285714285714
1.000000000000
0.333333333333
1.375000000000
Unreachable

Explanation

For node 2, it is best to jump from node 1 to node 2 with a danger factor of \dfrac{3}{11-1} = \dfrac{3}{10}.

For node 3, it is best to jump from node 2 to node 3 with a danger factor of \dfrac{2}{8-1} = \dfrac{2}{7}.

For node 4, it is best to jump from node 1 to node 4 with a danger factor of \dfrac{6}{11-5} = 1.

For node 5, it is best to jump from node 3 to node 5 with a danger factor of \dfrac{1}{7-4} = \dfrac{1}{3}.

For node 6, it is best to jump from node 1 to node 6 with a danger factor of \dfrac{11}{11-3} = \dfrac{11}{8}.

For node 7, it is impossible to jump to this node.


Comments

There are no comments at the moment.