Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2016 /finals /rng.html
wjomlex's picture
2016 Problems
07f695f verified
<p>
You're playing a video game that features <strong>N</strong> different areas, numbered from 1 to <strong>N</strong>.
There are <strong>M</strong> one-way paths that each connect two areas. The <strong>i</strong>th path runs from area
<strong>A<sub>i</sub></strong> to a different area <strong>B<sub>i</sub></strong>. No pair of paths directly connect the same pair of areas,
and for every area it's impossible to start at that area and follow a non-empty sequence of paths to return to that area. In other words, the game's layout is a directed acyclic graph.
</p>
<p>
You start in area 1. <strong>K</strong> other distinct areas each contain an item to collect &mdash; the <strong>i</strong>th of these is area <strong>I<sub>i</sub></strong>.
As soon as you've visited these <strong>K</strong> areas at least once each, you win! You'd like to do so as fast as possible.
</p>
<p>
At any point in time, if there are no outgoing paths leading away from your current area, you automatically respawn in area 1 after a delay of <strong>R</strong> seconds.
Otherwise, you get to choose one such path and attempt to follow it. Unfortunately, this game relies entirely on Random Number Generation to determine whether or not you'll be successful,
regardless of your skill. In particular, with probability <strong>P</strong>, you'll successfully travel along your chosen path for <strong>D</strong> seconds, ending up in a new area.
On the other hand, with probability 1 - <strong>P</strong>, you'll instead perish and respawn in area 1 after a delay of <strong>R</strong> seconds.
</p>
<p>
What's the minimum expected time for you to collect all <strong>K</strong> items, given that you play optimally? This is guaranteed to be possible &mdash;
that is, all <strong>K</strong> areas that contain items are reachable from area 1. Your output should have at most 10<sup>-6</sup> absolute or relative error.
</p>
<h3>Input</h3>
<p>
Input begins with an integer <strong>T</strong>, the number of times you play the game.
For each time, there is first a line containing the space-separated integers <strong>N</strong>, <strong>M</strong>, and <strong>K</strong>.
The second line contains the space-separated integers <strong>D</strong> and <strong>R</strong>.
The third line contains the real value <strong>P</strong> which is given with at most 4 decimal places.
The fourth line contains the <strong>K</strong> space-separated integers <strong>I<sub>1</sub></strong> to <strong>I<sub>K</sub></strong>.
Then, <strong>M</strong> lines follow, the <strong>i</strong>th of which contains the space-separated integers
<strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong>.
</p>
<h3>Output</h3>
<p>
For the <strong>i</strong>th time you play the game, print a line containing "Case #<strong>i</strong>: " followed by the expected time it will take you to collect all of the items
if you play optimally.
</p>
<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 50 <br />
2 &le; <strong>N</strong> &le; 100,000 <br />
1 &le; <strong>M</strong> &le; 100,000 <br />
1 &le; <strong>K</strong> &le; min(20, <strong>N</strong> - 1) <br />
0.5 &le; <strong>P</strong> &le; 1.0 <br />
1 &le; <strong>D</strong>, <strong>R</strong> &le; 1,000 <br />
1 &le; <strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong> &le; <strong>N</strong> <br />
2 &le; <strong>I<sub>i</sub></strong> &le; <strong>N</strong> <br />
</p>
<p>
The answer for each game is guaranteed to be less than 10<sup>30</sup>.
</p>
<h3>Explanation of Sample</h3>
<p>
In the first game, it takes you 10 seconds to reach the only item, and then you win. There's no chance of failure.
The second game is the same as the first, but now you fail to reach the item with probability 0.5. On average you will fail once before reaching the item, so you'll incur an average penalty of 3 seconds on top of the 10 seconds it takes you to succeed, for a total of 13 seconds.
</p>