Under construction

Still being built. Things may change

Fail Fast

Time limit4sMemory limit2048 MB

Summary
Order n tests with CPU costs, pass probabilities, and optional dependencies so the expected cost of a run that stops at the first failure is minimized.
Level

Medium7 of 10

Topics
Greedy, Tree, Sorting
Solved
No attempts yet

Problem

A large software project has many automated tests to help ensure quality. When a change is made to the source code, the tests run in some sequence to show that the change has not broken existing functionality. The change is accepted if and only if all tests pass.

Running all of these tests is costly, so as soon as one test fails, the remaining tests are not run. Each test takes a fixed amount of CPU time. The cost of a run that hits a failure is the sum of the CPU time of the tests up to and including the failing test. The cost of a run where all tests pass is 00.

A test may rely on the output of another single test. For example, test A may depend on the output of test B. In that case, test B must run before test A. Other tests may run between them.

Each test has a known probability of passing, based on an analysis of past data and an assessment of the code change. The probability of any test passing is independent of the probability of any other test passing. Given the CPU time to execute each test, the probability of each test's failure, and the dependencies, find an order in which to run the tests that minimizes the expected cost.

Input

The first line contains a single integer nn (1≤n≤1051\leq n\leq 10^5), the number of tests.

Each of the next nn lines contains three values: an integer cc (1≤c≤1061\leq c\leq 10^6), a real number pp (0<p<10<p<1), and an integer dd (0≤d≤n0\leq d\leq n). Here cc is the CPU time needed to run the test, pp is the probability that the test passes, and dd is the index of the test it depends on, or 00 if it has no dependency. Tests are indexed from 11 to nn in the order they are given.

Each probability has at most six decimal digits. There are no cyclic dependencies.

Output

Output nn lines, each containing a single integer: the indices of the tests in the order they should run. The expected cost of your order must be within 10−610^{-6} absolute or relative error of the optimal expected cost. Any order that meets this bound is accepted.

Examples1

  1. Example 1

    Input
    4
    100 0.5 0
    200 0.1 1
    10 0.5 2
    10 0.9 0
    
    Expected output
    4
    1
    2
    3