Signal Strength
Time limit1sMemory limit128 MB
Find the maximum signal strength reaching switch N-1 from switch 0 through a switch network with gain or loss multipliers on nodes and edges.
- Level
Medium5 of 10
- Topics
- Graph, DFS, Dynamic programming, Brute force
- Solved
- No attempts yet
Problem
Net Profits Incorporated has announced a new generation of network switching devices that support high-speed, instantly reconfigurable networks across long distances.
Each network is built from a new kind of switch. A switch watches several input lines, locks on to the strongest signal it receives, and forwards that signal to every output line connected to its output ports.
Because the connecting lines are long, signal loss is a major concern, and the switches themselves add further loss. To fight both, some switches carry amplifiers. To prevent destructive feedback, switches with amplifiers are never wired into a cycle in which their output could reach their own input, even indirectly.
Write a program that predicts the effective signal strength received at one point of a network when a signal is started at another point. You are given a network of switches (), numbered from . Each switch has a multiplier telling how much weaker or stronger its output is than the strongest input reaching it. A switch without an amplifier multiplies the strength by a factor of at least . A switch with an amplifier may multiply the strength by a factor as large as .
You are also given the connecting lines. Each line has a multiplier describing how much weaker the signal is at the end of the line than when it entered; these line multipliers are at least and at most .
Input
The input contains one or more networks.
Each network starts with a line holding a single integer , the number of switches; the switches are numbered starting at . A non-positive value of marks the end of the input and is not itself a network.
The next lines describe the switches in order. Each line begins with a floating-point number, the strength multiplier of that switch, followed by an integer , the number of lines attached to that switch's output. Then come pairs of numbers, one per output line: the first value of a pair is the number of the switch that receives the line as an input, and the second value is a floating-point multiplier for the signal loss along that line.
Output
For each network, print one line
Network M: X
where is the network's number (starting at ) and is the signal strength at the output of switch when a signal of strength is applied to (all) inputs of switch . If no signal ever reaches the output of switch , then is . Print with two digits after the decimal point.