#K48822. Can Travel To All Cities

    ID: 28506 Type: Default 1000ms 256MiB

Can Travel To All Cities

Can Travel To All Cities

You are given a network of cities represented as an undirected graph and a starting city. The graph has ( n ) cities (numbered from 0 to ( n-1 )) and ( m ) bidirectional roads. Each road connects two different cities. Determine whether it is possible to travel from the starting city to every other city without visiting any city more than once. In other words, check if the graph is connected when starting from the given city.

Input/Output Format:
The input is read from standard input (stdin) and the output is written to standard output (stdout). Use standard graph traversal techniques such as BFS (Breadth-First Search) or DFS (Depth-First Search) to solve this problem.

Note: If all cities can be reached, output True; otherwise, output False.

inputFormat

The first three lines of input are as follows:

  1. An integer (n), representing the number of cities.
  2. An integer (m), representing the number of roads.
  3. An integer (s), representing the starting city. This is followed by (m) lines, each containing two space-separated integers (u) and (v) which denote a bidirectional road between city (u) and city (v).

outputFormat

Output a single line with either True if it is possible to travel to all cities starting from the given city, or False otherwise.## sample

4
4
0
0 1
0 2
1 2
1 3
True