#K76532. Shipment Route Validator

    ID: 34663 Type: Default 1000ms 256MiB

Shipment Route Validator

Shipment Route Validator

You are given a proposed shipment route represented by a string of warehouse identifiers and a list of restricted consecutive warehouse pairs. A valid route should satisfy the following conditions:

  • No warehouse appears more than once. In other words, if the route is denoted by R, then for all i ≠ j, R[i] ≠ R[j].
  • No two consecutive warehouses form a pair that is in the restriction list. In mathematical notation, if the route is R and the set of restricted pairs is S, then for all i from 0 to n-2, it must hold that \( (R[i], R[i+1]) \notin S \).

If the route violates the first condition, output "Repeated warehouse". If the route violates the second condition, output "Consecutive restriction violation". Otherwise, output "Valid".

inputFormat

The input is given via standard input (stdin) and contains multiple lines:

  1. The first line contains a string representing the route. The string consists of uppercase letters, each representing a warehouse.
  2. The second line contains an integer m representing the number of restricted consecutive warehouse pairs.
  3. The following m lines each contain two uppercase letters separated by a space, representing a restricted pair where the order matters.

outputFormat

Output a single line to standard output (stdout) that is one of the following strings:

  • Valid
  • Repeated warehouse
  • Consecutive restriction violation
## sample
ABCD
2
A C
B D
Valid