This page is still under construction.

Parts of this page are still being built. What you see may change.

Hooking Up Power to the LEDs

Time limit1sMemory limit128 MB

Summary
Assign a voltage to each junction so every wire joins equal voltages and each LED drops between m and M, with the smallest possible highest voltage.
Level

Medium7 of 10

Topics
Shortest path, Union-find, Binary search
Solved
No attempts yet

Problem

You are in charge of the ACM ICPC closing ceremony. To decorate the auditorium, you hired a sentimental perfectionist designer.

A few hours later, a few hours before the ceremony starts, the designer tells you the decoration is done. What waits for you in the auditorium is a strangely shaped circuit. The designer starts explaining the meaning of life and the ACM ICPC hidden all over the circuit, and takes pride in how well the circuit works. You say "if this decoration does not work, the ceremony is completely ruined", and start looking for the power supply.

You: Where is the power supply?

Designer: Sorry? That is not my part! You are the one who has to supply the power. And never touch the circuit! Just connect power to the junctions. I have to report this perfect work to my manager. Goodbye.

The structure of an LED: anode and cathode

The structure of an LED: anode and cathode

You examine the circuit that was left behind.

An ordinary bulb glows whichever way the polarity goes, but an LED glows only when the polarity is right, that is, only when the anode pin sits at a higher voltage than the cathode pin. An LED has a minimum voltage, so even with the right direction it stays dark when the voltage across it is below that minimum. It also has a maximum voltage, and when the voltage across it goes above that maximum the part burns out.

Checking the circuit, you find that it is built from three kinds of parts.

  • LED: every LED in the circuit is the same type, so they share the same minimum voltage and maximum voltage.
  • Junction: the two pins of an LED connect to junctions. A junction connects wire endpoints as well as LED pins.
  • Wire: every wire has two endpoints, and each endpoint connects to a junction and carries voltage across.

Connecting external terminals at different voltages to the junctions supplies voltage to the circuit. Watch out for short circuits: the two endpoints of every wire must sit at the same voltage. Electromagnetics usually takes the lowest potential as 0, so you may treat every voltage as non-negative.

Now you have to buy a power supply that fits the circuit. Its price is proportional to the maximum voltage it can supply.

Given the description of an LED circuit, write a program that decides whether every LED can be lit without a short circuit and without burning an LED. When it can be done, the program also has to report the smallest maximum voltage that lights every LED.

Input

The input has several test cases. The first line of each test case has five integers JJ, LL, WW, mm, MM separated by spaces. JJ is the number of junctions (2≤J≤5002 \le J \le 500), LL is the number of LEDs (1≤L≤50001 \le L \le 5000), WW is the number of wires (0≤W≤50000 \le W \le 5000), and mm and MM are the minimum voltage and the maximum voltage of an LED (1≤m<M≤10001 \le m < M \le 1000). The junctions are numbered from 11 to JJ.

Each of the next LL lines has two integers separated by a space. The first is the number of the junction the anode pin of an LED connects to, and the second is the number of the junction its cathode pin connects to.

Each of the following WW lines has the numbers of the two junctions a wire joins, as two integers.

The input ends when 0 0 0 0 0 is read.

Output

Print one line for each test case.

If there is no way to light every LED, print Impossible. Otherwise print one integer, the smallest maximum voltage that lights every LED.

Hint

Potential difference and voltage mean the same thing in this problem.

Examples1

  1. Example 1

    Input
    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
    
    Expected output
    3
    3
    6
    3
    Impossible
    Impossible
    6
    2
    Impossible