TLE '16 Contest 1 P5 - Battle Plan

View as PDF

Submit solution


Points: 17 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types

Fax McClad, Croneria's most strategic bounty hunter, is planning an attack against the infamous Dankey Kang! Fax needs to successfully command squadrons of Kyuwing starfighters from various planets in order to defeat the vicious Dankey Kang Gang!

There are N planets, numbered from 1 to N, that are present today and Dankey Kang is hiding on planet N. Each planet i, excluding planet N, has a single one-way path to pi, another planet in the system, with a length of di spacemiles. It is guaranteed that every planet can reach planet N using some sequence of paths.

However, the lack of money is always stopping Fax from accomplishing his goals. In particular, he needs to ensure that expenses due to fuel costs are minimal. Each planet i, excluding planet N, has a fuel cost ci, signifying the cost of one unit of fuel for one Kyuwing. One unit of fuel is only enough to travel one spacemile, but Kyuwings have very large fuel tanks and can thus hold infinite amounts of fuel.

The battle is starting! Please help Fax determine the minimal cost of fuel per Kyuwing starting from all planets from 1 to N1.

Constraints

For all subtasks:

1ci,di100000

1piN

Subtask 1 [10%]

2N10

Subtask 2 [20%]

2N2000

Subtask 3 [70%]

2N100000

Input Specification

The first line will contain a single integer, N.

N1 lines of input follow. The ith line will contain three space-separated integers, pi, di, and ci.

Output Specification

The output will consist of N1 lines. The ith line should contain a single integer specifying the minimal fuel cost for a single Kyuwing starfighter starting from planet i travelling to planet N.

Sample Input

Copy
4
3 1 3
3 2 8
4 1 7

Sample Output

Copy
6
23
7

Comments

There are no comments at the moment.