Canadian Computing Competition: 2005 Stage 2, Day 1, Problem 2
You may remember the Spamway messaging service. Spamway uses a pyramid scheme of zombie computers to solicit and receive orders for their fine products. However, Spamway has a problem - all its zombies have gone on strike for better RAM. Hence, Spamway has recruited replacement scab zombies so that they can continue doing business during the strike. These scab zombies are very disorganized and hence are not very good at networking.
Your job is to organize the scab zombies so that Spamway can solicit and receive product orders in the minimum amount of time. Specifically, you are to assign to each zombie a list of subordinates so that:
- Each zombie except the head zombie has exactly one superior.
- Every zombie eventually reports to the head zombie.
To initiate a round of ordering, the head zombie will simultaneously send a message to all of its subordinates requesting a list of purchase orders. A scab zombie, upon receiving such a message, will make a similar request of all of its subordinates. After receiving a reply from all of its subordinates, the scab zombie will combine the purchase lists contained therein with the list of purchase orders it received and send the combined purchase list to its superior. So that you can organize the zombies, you need to know a few things:
- A zombie can send any number of messages simultaneously.
- Every message takes
seconds to reach its destination (all data is highly compressed to achieve this spectacular efficiency).
- Spamway has one manager who is not on strike and who can act as the head zombie (the manager is the infamous computer "localhost").
- All zombies use cellular modems to communicate. However, because of poor coverage, not all zombies can talk to each other.
- Spamway is very frugal and will not use more than
zombies (including the manager acting as head zombie).
- So that the scab zombies cannot be identified and harmed (with a
terrible virus) by the striking computers, all scab zombies are
given a secret code name:
and so on.
is the head zombie.
- Scab zombies, due to their lack of training, take a certain amount
of time to read a message once it has been received. Scab zombies
can read many messages simultaneously, but they cannot act on the
message before this reading is done. This lag time (called zombie
zzz time) varies for each zombie, but is a non-negative integer
number of seconds less than
. You can assume that zombie
(the head zombie) has no lag time.
Input Specification
Input begins with an integer value indicating the number of scab
zombies that have been hired (not counting the manager acting as head
zombie),
. This integer is followed by
lines, each
of which identifies the zombie
time for one particular zombie,
followed by the number of zombies that can be reliably contacted and
then a list of those zombies. The first line describes the head zombie,
and the remaining
lines describe zombies
through
, in that order.
Output Specification
Output should consist of a single integer value indicating the total amount of time that is needed to send and receive the data for a single round of ordering. While there may be several possible zombie organizations, you are to find and report the time for the optimal one.
Sample Input 1
3
0 2 1 3
50 1 0
7 1 3
3 2 0 2
Sample Output 1
70
Explanation
There is only one organization available: 's subordinates are
and
;
and
have no subordinates, and
's only subordinate is
.
- When
decides to initiate a round of ordering (let us call this time "
"), it sends off an order request to
and
.
- At time
,
and
receive the message.
takes three seconds to read the message, and, at time
,
has read the message and it fires off a request to its subordinate,
.
- At time
,
receives
's message, and has to think for seven seconds.
- At time
,
is done thinking.
has no subordinates, so it sends its order list to its superior
.
- At time
,
receives the order list, and has to think for three seconds.
- At time
, then,
combines
's order list with its own and sends the combined order list to
, and it is received at time
.
- At time
, after fifty seconds of thought,
has finished reading
's initial message.
promptly sends its order list to
, which receives the list at time
. After receiving this message,
is in possession of all of the purchase orders sent to Spamway, thus terminating the round of ordering.
Sample Input 2
6
0 4 1 2 3 4
7 2 0 4
12 3 0 5 6
3 2 0 6
4 2 0 1
100 1 2
10 2 2 3
Sample Output 2
164
Comments