#C12005. Flight Route Connectivity

    ID: 41385 Type: Default 1000ms 256MiB

Flight Route Connectivity

Flight Route Connectivity

You are given a list of country abbreviations and a set of direct flights connecting these countries. Each flight represents an undirected connection between two countries. Your task is to determine whether it is possible to travel from a given start country to a given end country using one or more of these direct flights.

This problem can be modeled as a graph connectivity issue where each country is represented by a node and a direct flight is represented by an undirected edge between nodes. You are required to answer whether a valid path exists between the start and end nodes using the provided flight connections.

Note: The input and output will be handled through standard input (stdin) and standard output (stdout), respectively.

inputFormat

The input consists of the following:

  • An integer n representing the number of countries.
  • A single line containing n space-separated country abbreviations.
  • An integer m representing the number of direct flights.
  • m lines, each containing two space-separated country abbreviations indicating a direct flight between them.
  • A line containing the start country abbreviation.
  • A line containing the end country abbreviation.

Example:

4
USA CAN MEX BRA
3
USA CAN
CAN MEX
MEX BRA
USA
BRA

outputFormat

Output a single line with True if there exists a sequence of direct flights connecting the start country to the end country. Otherwise, output False.

Example:

True
## sample
3
USA CAN MEX
1
USA CAN
USA
CAN
True