Problem G
Treasure Diving
Legends often tell of great treasures. But you rarely get
the chance to actually stumble upon those treasures. Most of
them are lost in the sea, or hidden below mountains. But as you
learned from one of your biggest idols, treasures do belong
into a museum. And now you have the chance to make that
happen.
On an expedition you found a large cave network. A native
shaman has spoken about incredible values his ancestors have
hidden in the caves. He even gave you an ancient map, depicting
the cave network and the location of the treasures within.
Sadly, the cave network is completely flooded. Since the trip
out here takes forever, you decided to do a short dive and
scout out the cave network. But on your arrival back at the
entrance to the cave network you get the news
That puts you on the spot. You only have a short time left,
and only one lousy tank of air. So it is all on you. You only
have time for a single dive. But how could you possible decide
which route to take? The cave network is huge, and you should
definitely try and rescue as much of the treasures as possible.
You think back to your times as a computer scientist at the
university
You may assume that neither locating or picking up a treasure within a cave nor the traversal of a cave consumes any air.
Input
Each test set consists of multiple test cases. The file
starts with a single number
Output
For each test case print a number
Sample Input 1 | Sample Output 1 |
---|---|
3 5 3 0 1 10 0 2 20 0 3 30 4 1 2 3 4 30 5 3 0 1 10 0 2 20 0 3 30 4 1 2 3 4 60 5 3 0 1 10 0 2 20 0 3 30 4 1 2 3 4 10000 |
1 2 3 |