#C1951. Fully Connected Dungeon Check

    ID: 45213 Type: Default 1000ms 256MiB

Fully Connected Dungeon Check

Fully Connected Dungeon Check

You are given a dungeon with n rooms numbered from 0 to n-1 and a list of undirected connections between them. Each connection represents a bidirectional passage between two rooms. The dungeon is said to be fully connected if every room can be reached from room 0 using these passages.

Your task is to determine whether the dungeon is fully connected.

Definition:

  • Let \( G = (V, E) \) be an undirected graph where \( V = \{0, 1, \ldots, n-1\} \) and \( E \) is the set of connections.
  • The dungeon is fully connected if and only if for every room \( i \) in \( V \), there exists a path from room 0 to room \( i \).

Determine if the dungeon meets this criterion.

inputFormat

The input is read from standard input (stdin) and has the following format:

 n m
 u1 v1
 u2 v2
 ...
 um vm

Here, the first line contains two integers n (the number of rooms) and m (the number of connections).

Each of the following m lines contains two space-separated integers u and v which represent a bidirectional connection between room u and room v.

outputFormat

Print a single line to standard output (stdout):

  • True if the dungeon is fully connected (i.e., every room is reachable from room 0).
  • False otherwise.
## sample
5 4
0 1
0 2
1 3
3 4
True