#NOI2014F. 购票 (Buying Tickets)

购票 (Buying Tickets)

Description

This Summer, NOI is celebrating its 30th birthday in the city of SZ(Shenzhen). OIers attending this ceremony are travelling to SZ from nn cities around the country.

The cities in the country form a rooted tree with SZ as its root, and each city is connected to its parent by a road. For simplicity, we label the nn cities with integers from 11 to nn. SZ city has a label of 11. For any city other than SZ labelled vv, its parent on the tree fvf_v and length of the road to its parent SvS_v is given.

To arrive in SZ from city vv, we first choose one of vv's ancestors, aa, and pay for a ticket to aa. Then we choose aa's ancestor bb and pay to arrive in bb. Repeat this process until SZ is reached.

For each city vv, a limit on travel distance lvl_v is given. For aa as an ancestor of vv, a direct transportation from city vv to city aa could be taken only if the sum of roads' distances between them is not greater than lvl_v; otherwise it cannot be reached within one travel. For each city vv, parameters of transportation price pv,qvp_v,q_v are also known. if the total distance of roads from city vv to city aa is dd, then the price of ticket from city vv to city aa is dpv+qvdp_v+q_v.

OIers from every city want to spend less money to get to SZ. Your task is to tell them the minimum cost for OIers in each city.

Input Format

The first line contains two integers n,tn,t, indicating the number of cities and a brief description of input data (meaning explained later).

Each line from line 22 to line nn describes a city other than SZ. Line vv consists of five non-negative integers fv,Sv,pv,qv,lvf_v,S_v,p_v,q_v,l_v, indicating the parent of city vv, the distance between them, the two parameters for ticket price, and the limitation on travel distance respectively.

Note: Input does not contain city 11, SZ. line 22 to line nn describes city 22 to city nn.

Output Format

The output consists of n1n-1 lines, each with one integer. Line vv is the minimum cost to travel from city v+1v+1 to SZ.

Also Note: Output does not contain city 11, SZ.

7 3
1 2 20 0 3
1 5 10 100 5
2 4 10 10 10
2 9 1 100 10
3 5 20 100 10
4 4 20 0 10
40
150
70
149
300
150

Constraints and Hint

For all the data, n2×105n \leq 2 \times 10^5, 0pv1060 \leq p_v \leq 10^6, 0qv10120 \leq q_v \leq 10^{12}, 1fv<v1 \leq f_v < v, 0<svlv2×10110 < s_v \leq l_v \leq 2 \times 10^{11}, and the total distance from any city to SZ is not greater than 2×10112 \times 10^{11}.

tt in input describes input type, 0t<40 \leq t < 4:

When t=0t=0 or 22, for every city vv in input, fv=v1f_v=v-1, therefore the cities form a chain with SZ on one end;

When t=0t=0 or 22, for every city vv in input, lv=2×1011l_v=2 \times 10^{11}, therefore there's no limit on travel distance, all cities could travel directly to any of their ancestors;

When t=3t=3, no special case is expected.