#C9645. Forming a Spanning Tree from Island Bridges
Forming a Spanning Tree from Island Bridges
Forming a Spanning Tree from Island Bridges
You are given a set of islands and bridges connecting some pairs of islands. Your task is to determine if it is possible, by removing some bridges if necessary, to create a structure that connects all islands such that there is exactly one distinct path between every pair of islands, i.e. a spanning tree.
Note that a spanning tree on ( n ) vertices must have exactly ( n - 1 ) edges. Moreover, even if there are extra bridges, you can choose a subset of them to form the spanning tree, but the underlying graph must be connected.
inputFormat
The first line contains two integers ( n ) and ( e ) where ( n ) is the number of islands and ( e ) is the number of bridges. Each of the next ( e ) lines contains two integers ( u ) and ( v ) indicating that there is a bridge between island ( u ) and island ( v ). Input is provided via standard input (stdin).
outputFormat
Output a single line: "Yes" if it is possible to form a spanning tree (i.e. a tree connecting all islands), or "No" otherwise. The answer should be printed to standard output (stdout).## sample
5 5
1 2
1 3
3 4
4 5
2 5
Yes
</p>