Under construction

Still being built. Things may change

Zoo Management

Time limit5sMemory limit1024 MB

Summary
Decide whether animals can move along tunnels, in simultaneous cycles, from their starting enclosures to the target arrangement.
Level

Medium7 of 10

Topics
Graph, DFS, Hash map
Solved
No attempts yet

Problem

When managing a zoo, you sometimes want to move animals between enclosures. For example, the zebras may like the spacier enclosure currently occupied by the penguins, the penguins may want to move to the colder enclosure where the koalas live, and the koalas will move to an empty enclosure filled with eucalyptus. You would move the koalas first to free the colder enclosure, then move the penguins there, and finally move the zebras.

Animals move through special tunnels that connect the enclosures. They must never go outside, because they may get scared or run away and hurt themselves.

Now every enclosure is full, which makes moving animals much harder. For example, if the koalas had to move into the former zebra enclosure, no animal could move first. Instead, the animals move at the same time. The zebras, koalas, and penguins start down different tunnels together and arrive at their new enclosures together, so they never meet. You cannot simply swap the animals in two connected enclosures, because they would meet in the tunnel and become scared.

You can, any number of times, choose a set of animals and move each one to an adjacent enclosure through a tunnel, as long as the animal in that enclosure also moves in the same move. No tunnel may be used more than once in the same move. Is it possible to reach the desired arrangement in a series of moves?

Input

The first line contains two integers nn (1≤n≤4⋅1051 \le n \le 4 \cdot 10^5) and mm (0≤m≤4⋅1050 \le m \le 4 \cdot 10^5), the number of enclosures and tunnels. The next nn lines each contain two integers bib_i (1≤bi≤1061 \le b_i \le 10^6) and eie_i (1≤ei≤1061 \le e_i \le 10^6), the type of animal in enclosure ii at the start and the type of animal you want in enclosure ii after all moves. It is guaranteed that e1,…,ene_1, \dots, e_n is a permutation of b1,…,bnb_1, \dots, b_n. The next mm lines each contain two integers xx and yy (1≤x<y≤n1 \le x < y \le n), meaning enclosures xx and yy are connected by a two-way tunnel. No two enclosures are connected by more than one tunnel.

Output

If it is possible to move the animals so that every enclosure contains the desired animal type, print possible. Otherwise, print impossible.

Examples4

  1. Example 1

    Input
    3 3
    1 4
    4 7
    7 1
    1 2
    2 3
    1 3
    
    Expected output
    possible
    
  2. Example 2

    Input
    2 1
    1 2
    2 1
    1 2
    
    Expected output
    impossible
    
  3. Example 3

    Input
    5 6
    10 40
    20 30
    30 50
    40 20
    50 10
    1 2
    2 3
    1 3
    3 4
    3 5
    4 5
    
    Expected output
    possible
    
  4. Example 4

    Input
    4 4
    10 10
    10 20
    20 10
    20 20
    1 2
    2 3
    3 4
    1 4
    
    Expected output
    impossible