Problem M
Fail Fast
A large software project has been written with many automated tests to help ensure quality. When a change is made to the source code, all of the automated tests are run in some sequence to help show that the code change has not broken some pre-existing functionality. The code change is accepted if and only if all automated tests pass.
Running all of these automated tests is costly, so as soon
as there is one failure, the remaining tests are not run. Each
test takes a certain amount of CPU time to perform. The cost of
running a sequence of tests when there is a test failure is the
sum of the CPU time used by the automated tests up to and
including the failing test. The cost of running a sequence of
tests where all tests pass is equal to
A given automated test may rely on the output of another single automated test. For example, automated test A may depend on the output of automated test B. In such a case, test B must be executed before test A. Note that other tests may be run between test B and test A.
Based on an analysis of past data and an assessment of the code change, each automated test has a known probability of passing. The probability of any given 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, determine an order in which the tests should be executed, sequentially, to minimize the expected cost of running the sequence of tests.
Input
The first line of input contains a single integer
Each of the next
Each probability is specified with at most six decimal digits. There are no cyclic dependencies.
Output
Output
Sample Input 1 | Sample Output 1 |
---|---|
4 100 0.5 0 200 0.1 1 10 0.5 2 10 0.9 0 |
4 1 2 3 |