eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

It`s Ir-Resist-Able

It`s Ir-Resist-Able

A common component in electronic circuits is the resistor. Each resistor has two terminals, and when current flows through a resistor, some of it is converted to heat, thus "resisting" the flow of the current. The extent to which it does this is indicated by a single positive numeric value, cleverly called the \textit{resistance} of the resistor. By the way, the units of resistance are Ohms. Here's what a single resistor looks like in a diagram of an electronic circuit: \includegraphics{https://static.e-olymp.com/content/df/df1fae89bf821edf8bf36e992ba2186b86546b45.jpg} When two resistors are connected in series, as shown below, then their equivalent resistance is just the sum of the resistances of the individual resistors. For example, if the two resistors below had resistances of \textbf{100} and \textbf{200} Ohms, respectively, then the combined resistance (from point \textbf{A} to point \textbf{B}) would be \textbf{300} Ohms. Of course, combining three or more resistors in series would yield a resistance equal to sum of all the individual resistances. \includegraphics{https://static.e-olymp.com/content/f0/f0940ac216970bdaa99d05dee9dcb35e75aef4c1.jpg} Resistors may also be connected in parallel, like this: \includegraphics{https://static.e-olymp.com/content/1c/1ce5e3403653dfa812ecfd610248aeff6aa510b7.jpg} If these two resistors had resistances of \textbf{100} and \textbf{150} Ohms, then the parallel combination would yield an equivalent resistance between points \textbf{A} and \textbf{B} of \includegraphics{https://static.e-olymp.com/content/20/20062a8b4dcfd65753f876031ee72feb098de588.jpg} Connecting three resistors in parallel uses the same rule, so a \textbf{100} Ohm, \textbf{150} Ohm, and \textbf{300} Ohm resistor in parallel would yield a combined resistance of just \textbf{50} Ohms --- that is, \textbf{1/(1/100+1/150+1/300)} Ohms. In this problem you're provided one or more descriptions of resistors and their interconnections. Each possible interconnection point (the terminals of a resistor) is identified by a unique positive integer, its label. And each resistor is specified by giving its two interconnection point labels and its resistance (as a real number). For example, the input \textbf{1 2 100} would tell us that a \textbf{100} Ohm resistor was connected between points \textbf{1} and \textbf{2}. A pair of resistors connected in series might be specified like this: \textbf{1 2 100} \textbf{2 3 200} Here we've got our \textbf{100} Ohm resistor connected at points \textbf{1} and \textbf{2}, and another \textbf{20}0 Ohm resistor connected to points \textbf{2} and \textbf{3}. Two resistors in parallel would be similarly specified: \textbf{1 2 100} \textbf{1 2 150} Once you know how the resistors are interconnected, and the resistance of each resistor, it's possible to determine the equivalent resistance between any two points using the simple rules given above. In some cases, that is. Some interconnections of resistors can't be solved using this approach - you won't encounter any of these in this problem, however. \textbf{Notes} Be aware that there may be input test cases with some resistors that don't contribute to the overall resistance between the indicated points. For example, in the last case shown in the Sample Input section below, the resistor between points \textbf{1} and \textbf{2} is unused. There must be some flow through a resistor if it is to contribute to the overall resistance. No resistor will have its ends connected together. That is, the labels associated with the ends of a resistor will always be distinct. \InputFile There will be one or more cases to consider. Each will begin with a line containing three integers \textbf{N}, \textbf{A}, and \textbf{B}. \textbf{A} and \textbf{B}indicate the labels of points between which you are to determine the equivalent resistance. \textbf{N} is the number of individual resistors and will be no more than \textbf{30}. \textbf{N}, \textbf{A} and \textbf{B} will all be zero in the line following the last case. Following each "\textbf{N A B}" line will be \textbf{N} lines, each specifying the labels of the points where a resistor is connected, and the resistance of that resistor, given as a real number. \OutputFile For each input case, display a line that includes the case number (they are numbered sequentially starting with \textbf{1}) and the equivalent resistance, accurate to two decimal places.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
2 1 3
    1 2 100
    2 3 200

2 1 2
    1 2 100
    1 2 150

6 1 6
    1 2 500
    1 3 15
    3 4 40
    3 5 100
    4 6 60
    5 6 50

0 0 0
Вихідні дані #1
Case 1: 300.00 Ohms
Case 2: 60.00 Ohms
Case 3: 75.00 Ohms