#C9450. Archipelago Connectivity

    ID: 53545 Type: Default 1000ms 256MiB

Archipelago Connectivity

Archipelago Connectivity

You are given an archipelago with \( n \) islands and \( m \) one-way ferry routes. The archipelago is considered connected if for every pair of islands \( (u,v) \), there exists a route from \( u \) to \( v \); that is, the directed graph is strongly connected. Note that an archipelago with a single island is trivially connected.

The input consists of several datasets. Your task is to determine whether each archipelago is connected. For each dataset, output CONNECTED if the archipelago is connected, or DISCONNECTED otherwise.

inputFormat

The input contains several datasets. Each dataset begins with a line containing two integers \( n \) and \( m \), representing the number of islands and the number of one-way ferry routes respectively. This is followed by \( m \) lines, each containing two integers \( u \) and \( v \), indicating a ferry route from island \( u \) to island \( v \). The input terminates with a line containing "0 0" which should not be processed.

outputFormat

For each dataset, print a single line containing either CONNECTED if the archipelago is strongly connected, or DISCONNECTED otherwise.

## sample
4 4
1 2
2 3
3 4
4 1
4 3
1 2
2 3
3 1
0 0
CONNECTED

DISCONNECTED

</p>