#C3248. Are All Colonies Reachable?
Are All Colonies Reachable?
Are All Colonies Reachable?
You are given a set of N colonies numbered from 1 to N and M bidirectional corridors connecting these colonies. Starting from the colony S, your task is to determine whether every colony is reachable.
The problem can be modeled as determining if the undirected graph is connected. In other words, check whether for every colony \(i\) (where \(1 \le i \le N\)), there exists a path from the starting colony \(S\) to \(i\).
Input Format: The first line of input contains three integers: \(N\), \(M\), and \(S\). The next \(M\) lines each contain two integers \(u\) and \(v\), indicating that there is a corridor connecting colony \(u\) and colony \(v\).
Output Format: Output a single line with the string "Yes" if all colonies are reachable from \(S\), and "No" otherwise.
Note: All formulas are presented in \(\LaTeX\) format.
inputFormat
The first line contains three integers \(N\), \(M\), and \(S\) separated by spaces.
Each of the next \(M\) lines contains two integers \(u\) and \(v\), representing a corridor between colony \(u\) and colony \(v\).
You can assume that \(1 \leq S \leq N\) and the graph has no self-loops or duplicate edges.
outputFormat
Output a single line containing "Yes" if every colony is reachable from the starting colony \(S\), and "No" otherwise.
## sample6 5 1
1 2
2 3
3 4
4 5
5 6
Yes