#C9198. Connected Components in an Undirected Graph

    ID: 53264 Type: Default 1000ms 256MiB

Connected Components in an Undirected Graph

Connected Components in an Undirected Graph

This problem requires you to compute the number of connected components in an undirected graph. A connected component is a set of vertices where every vertex is reachable from any other vertex in the same set. You are given the number of vertices and edges, followed by the edge list. Use standard techniques such as depth-first search (DFS) or breadth-first search (BFS) to determine the number of connected components.

The graph is provided with vertices numbered from 1 to \(n\). If there are no edges, every vertex forms a separate connected component.

inputFormat

The first line of input contains two integers (n) and (m), the number of vertices and edges respectively. Each of the following (m) lines contains two integers (u) and (v) denoting an undirected edge between vertices (u) and (v).

outputFormat

Output a single integer representing the number of connected components in the graph.## sample

4 0
4