Painting vertices

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

Input

Input consists of several cases. Every case begins with the number of
vertices n, the starting vertex x and the final vertex y. Next comes a
number m, followed by m different arcs u v where u ≠ v. Follow a number
p, followed by the p vertices initially painted. Assume 2 ≤ n ≤ 10⁴,
x ≠ y, 0 ≤ m ≤ 5n, and 0 ≤ p ≤ 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 x to y that only passes through painted vertices, x
and y included. If it is impossible, state so.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:52:30.123Z

© Jutge.org, 2006–2026.
https://jutge.org
