Odd Opportunities

Interview

Time limit1sMemory limit128 MB

Summary
Given a graph and a parity requirement (odd or even degree) for every vertex, decide whether some subset of edges can be kept so each vertex meets its required degree parity.
Level

Medium7 of 10

Topics
Graph, Union-find, Math, Implementation
Solved
No attempts yet

Problem

A secret worldwide organization operates in complete secrecy. Each member keeps contact with some of the other members, but not necessarily with all of them.

The newly elected head of the organization has a plan to make it even more secretive: some members will have to drop some of their contacts and stop communicating with them. What matters is only whether the number of contacts each member keeps ends up odd or even. Every member has been told whether the number of contacts they keep must be odd or must be even.

Your task is to decide whether the members can drop contacts so that every member's parity requirement is satisfied.

Input

The input consists of several scenarios. Each scenario starts with a line containing two integers VV and EE: VV is the number of members (1≤V≤100001 \le V \le 10000) and EE is the number of contacts (0≤E≤V⋅(V−1)/20 \le E \le V \cdot (V - 1) / 2).

Each of the next EE lines contains two integers v1v_1 and v2v_2 (1≤v1,v2≤V1 \le v_1, v_2 \le V, v1≠v2v_1 \ne v_2), meaning there is a contact between members v1v_1 and v2v_2. No pair of members appears more than once.

The next line contains exactly VV lowercase characters. The ii-th character describes member ii and is either o (the number of contacts kept must be odd) or e (the number of contacts kept must be even).

The last scenario is followed by a line containing two zeros.

Output

For each scenario, print possible if the members can drop contacts so that every member keeps a number of contacts of the required parity, and impossible otherwise. Print each answer on its own line.

Examples2

  1. Example 1

    Input
    5 6
    1 2
    2 3
    3 4
    4 5
    1 3
    1 4
    oeooo
    3 1
    1 2
    oeo
    5 0
    eeeee
    5 0
    eeoee
    5 0
    eeoeo
    4 2
    1 2
    4 3
    eeee
    0 0
    
    Expected output
    possible
    impossible
    possible
    impossible
    impossible
    possible
    
  2. Example 2

    Input
    1 0
    o
    0 0
    
    Expected output
    impossible