Painting vertices P76043


Statement
 

pdf   zip

You are given a directed graph, where some vertices are initially painted and some are not, and two vertices xx and yy. Please paint the minimum number of additional vertices so that there is a path from xx to yy that only passes through painted vertices.

Input

Input consists of several cases. Every case begins with the number of vertices nn, the starting vertex xx and the final vertex yy. Next comes a number mm, followed by mm different arcs uu vv where uvu \ne v. Follow a number pp, followed by the pp vertices initially painted. Assume 2n1042 \le n \le 10^4, xyx \ne y, 0m5n0 \le m \le 5n, and 0pn0 \le p \le n. The vertices are numbered starting at 0.

Output

For every case, print the minimum number of vertices to paint so that there is a path from xx to yy that only passes through painted vertices, xx and yy included. If it is impossible, state so.

Public test cases
  • Input

    2 1 0
    1  1 0
    0
    
    2 0 1
    0
    2  0 1
    
    5 0 2
    6  0 1  1 2  0 3  3 1  3 4  4 2
    4  0 3 4 2
    
    8 7 0
    11  4 1  6 0  7 4  5 3  7 5
    1 6  6 7  0 2  5 1  4 2  3 6
    3  6 4 2
    

    Output

    2
    impossible
    0
    3
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++