#K90882. Connected Ribbons

    ID: 37851 Type: Default 1000ms 256MiB

Connected Ribbons

Connected Ribbons

You are given n ribbons and m connections. Each connection links two ribbons. The ribbons are numbered from 1 to n. Your task is to determine whether all the ribbons are connected together forming one single chain.

More formally, you are given two integers \(n\) and \(m\) followed by \(m\) pairs of integers \((u,v)\) which indicate that ribbon \(u\) is connected to ribbon \(v\). The connectivity is bidirectional. Check if it is possible to travel between any two ribbons using the given connections.

Note:

  • If there are no connections and \(n > 1\), the ribbons are considered DISCONNECTED.
  • A single ribbon (\(n = 1\)) is trivially connected.

inputFormat

The input is given from standard input in the following format:

n m
u1 v1
u2 v2
... 
um vm

Where:

  • \(n\) is the number of ribbons.
  • \(m\) is the number of connections.
  • Each of the next \(m\) lines contains two integers \(u\) and \(v\) representing a connection between ribbons \(u\) and \(v\).

outputFormat

Print a single line to standard output:

  • CONNECTED if all the ribbons are connected.
  • DISCONNECTED otherwise.
## sample
5 4
1 2
2 3
3 4
4 5
CONNECTED