#K13676. Bidirectional Communication in Networks
Bidirectional Communication in Networks
Bidirectional Communication in Networks
In this problem, you are given a directed graph representing a network of computers and a central server. The computers are numbered from 1 to ( n ), where computer 1 acts as the central server. Each directed edge represents a one-way communication link between computers. Your task is to determine whether every computer can communicate with the server and vice versa.
Formally, you are to check if the following condition holds:
$$\text{For every } i \in \{1, 2, \dots, n\}, \quad \text{there exists a path from } 1 \text{ to } i \quad \text{and} \quad \text{there exists a path from } i \text{ to } 1. $$If both conditions are met, output "YES"; otherwise, output "NO".
inputFormat
The input is read from standard input and has the following format:
The first line contains two integers ( n ) and ( m ), representing the number of nodes (computers) and the number of directed edges respectively. Each of the next ( m ) lines contains two integers ( u ) and ( v ), representing a directed edge from node ( u ) to node ( v ).
outputFormat
Output a single line to standard output containing either "YES" if every computer can communicate with the server in both directions, or "NO" otherwise.## sample
6 7
1 2
2 3
3 4
4 5
5 6
6 1
4 2
YES