eolymp
bolt
Try our new interface for solving problems
Məsələlər

LED Circuit

LED Circuit

\includegraphics{https://static.e-olymp.com/content/00/00fe1ea61c3a7c74b3ed37e5a7348668f9b8cb15.jpg} You are in charge of preparing the conference hall for the closing ceremony of ACM ICPC. You had hired a perfectionist sentimental room designer to design an elegant decoration for the old hall. The ceremony is going to start in a few hours and the designer has just informed you of the completion of the decoration. When you reach the conference hall, you confront a strange circuit on the wall. The designer starts explaining the meanings of life and ACM ICPC hidden under each piece of the circuit. The circuit consists of LEDs (Light Emitting Diodes) interconnected with junctions and wires. You ask whether the LEDs should be switched on. "\textit{Of course!}" the designer responds, "\textit{Each and every LED must be lit, otherwise the whole work is junk!}" You look around the circuit to find its power plug. - \textit{Where is the power plug?} - \textit{Huh? It’s beyond the scope of my work! It is you who has to provide the electricity to the LEDs. And be careful! Do not remove or modify a single part of the circuit; Just connect power supply cables to the junctions. I have to leave right now. I will send a report of my perfect work to your manager. Bye.} Left alone with the bizarre circuit, you start inspecting the circuit. \includegraphics{https://static.e-olymp.com/content/56/56dfd04b3aac114eb4eaaee0a03f749d66f56431.jpg} Unlike incandescent light bulbs, which emit light regardless of the electrical polarity, LEDs only emit light with the correct electrical polarity (i.e. when their anode pin has a higher electric potential than the cathode pin). Each LED has a minimum voltage. An LED does not emit (even with the correct polarity) if the electrical potential difference of its pins is less than its minimum voltage. Each LED has also a maximum voltage. An LED is destroyed if its electrical potential difference exceeds its maximum voltage. Your inspection on the circuit shows it consists of three types of components: \begin{itemize} \item LEDs: Fortunately, all LEDs of the circuit are of the same type, and so having the same minimum voltage, and the same maximum voltage. \item Junctions: Each of the two pins of an LED in the circuit is connected to a junction. Junctions are not only a place for connecting the LED pins, but also for connecting the wire end-points. \item Wires: Each wire has two end-points and connects a junction directly to another junction forcing them to have the same electric potential. \end{itemize} By connecting external electrical poles (with different values of voltage) to each of the junctions of the circuit, you can inject different electric potentials to the junctions. Note that each junction must be connected to an external electrical pole. Be careful of \textit{short circuits}: the end-points of each wire MUST have the same electric potential. By convention, we can assume the minimum electric potential to be zero. So, all the electric potentials can be considered to be nonnegative. Now, you have to buy an external power supply that provides you with the required electrical poles. The cost of such power supplies depends on their \textit{upper-bound}: the maximum voltage they provide. Given the specification of the LED circuit, you have to write a program that tests if it is possible to light all the LED s\textit{correctly} (with no short circuits, and no LED destruction). In the case of the possibility, the program should also compute the minimum possible upper-bound of power supply with which all LEDs can emit light. \InputFile The input consists of several test cases. Each test case describes an LED circuit and starts with a line containing \textbf{5 }space-separated integers \textbf{J}, \textbf{L}, \textbf{W}, \textbf{m}, and \textbf{M}, where \textbf{J} is the number of junctions (\textbf{2} ≤ \textbf{J} ≤ \textbf{500}), \textbf{L} is the number of LEDs (\textbf{1} ≤ \textbf{L} ≤ \textbf{5000}), \textbf{W} is the number of wires (\textbf{0} ≤ \textbf{W} ≤ \textbf{5000}), and \textbf{m} and \textbf{M} are the minimum and maximum voltage of LEDs respectively (\textbf{1} ≤ \textbf{m} < \textbf{M} ≤ \textbf{1000}). Assume that the junctions are numbered \textbf{1} through \textbf{J}. Each of the next \textbf{L} lines represents an LED with two space-separated integers. The first integer is the number of the junction to which the anode pin of the LED is connected and the second integer is the number of the junction for the cathode pin. Then, \textbf{W} lines follow, each describing a wire of the circuit using two space-separated integers: the junctions the wire directly connects. The input terminates with a line containing "\textbf{0 0 0 0 0}" (omit the quotes). \OutputFile Write a single line of output for each test case. If there is no way to correctly light all the LEDs in the circuit of that test case, only write the word "\textbf{Impossible}" (with no quotes). Otherwise, write a single integer: the minimum upper-bound of power supply with which all the LEDs can be lit.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2 1 0 3 5
1 2
3 2 0 3 5
1 2
3 2
3 2 0 3 5
3 2
1 3
3 1 1 3 5
1 2
2 3
3 1 2 3 5
1 2
2 3
3 1
3 3 0 3 5
1 2
2 3
1 3
3 3 0 3 6
1 2
2 3
1 3
4 2 2 2 7
1 2
3 4
3 1
2 4
4 2 2 2 7
1 2
3 4
3 2
1 4
0 0 0 0 0
Çıxış verilənləri #1
3
3
6
3
Impossible
Impossible
6
2
Impossible
Mənbə 38th ACM International Collegiate Programming Contest, 2013–2014 Asia Region, Tehran Site, Sharif University of Technology, 19–20 December 2013