#K56617. Walkathon Completion Check
Walkathon Completion Check
Walkathon Completion Check
You are given a directed graph representing available paths between waypoints in a walkathon. Each path is represented by a pair of waypoints indicating a direct route from one point to another. Given a sequence of visited waypoints, determine whether the sequence represents a valid completion of the walkathon. That is, for every consecutive pair of waypoints in the sequence, there must exist a direct path from the first to the second.
Formally, let \(P\) be the set of directed paths. A sequence \(S = [s_1, s_2, \dots, s_n]\) is valid if and only if for every \(i\) from 1 to \(n-1\), the edge \((s_i, s_{i+1})\) is in \(P\). If the sequence is valid, output completed
; otherwise, output not completed
.
inputFormat
The input is read from stdin and has the following format:
m path_1 path_2 ... path_m n s_1 s_2 ... s_n
Here, the first line contains an integer m
representing the number of available paths. The following m
lines each contain two strings separated by a space, representing a directed path from the first waypoint to the second.
The next line contains an integer n
which is the number of waypoints in the sequence. The last line contains n
waypoints separated by spaces, representing the sequence of visited waypoints.
outputFormat
Output a single line to stdout containing either completed
if the sequence is valid or not completed
otherwise.
5
start A
A B
B C
C end
D E
5
start A B C end
completed