#K88612. Landmark Navigation
Landmark Navigation
Landmark Navigation
You are given a directed graph representing intersections connected by one-way roads. Anna has a list of landmarks she wishes to visit in a specified order. Your task is to determine if it is possible for Anna to travel through the city by moving from one landmark to the next using the available directed roads.
Formally, you are provided with a directed graph consisting of (n) intersections and (m) roads. You are also given a sequence of landmarks (L_1, L_2, \dots, L_k). For each consecutive pair (L_i) and (L_{i+1}), check if there exists a path from (L_i) to (L_{i+1}) following the road directions. If such a path exists for every pair, output "possible"; otherwise, output "impossible".
inputFormat
The input is read from standard input (stdin) and has the following format:
(n) (m)
Next (m) lines: Each line contains two integers (u) and (v) representing a directed road from intersection (u) to intersection (v).
Next line: An integer (L) indicating the number of landmarks.
Next line: (L) integers representing the sequence of landmarks Anna wants to visit in order.
outputFormat
Print a single line to standard output (stdout) containing either "possible" if Anna can visit all the landmarks in the specified order, or "impossible" otherwise.## sample
5 6
1 2
2 3
3 4
4 5
2 4
1 3
4
1 3 4 5
possible