#C4074. Count Connected Components

    ID: 47572 Type: Default 1000ms 256MiB

Count Connected Components

Count Connected Components

You are given an undirected graph with \(N\) nodes and \(M\) edges. Your task is to calculate the number of connected components in the graph. Two nodes are considered to be in the same connected component if there exists a path between them using the given edges.

Note: A connected component is a set of nodes such that there is a path connecting any two nodes in the component. If a node has no connecting edges, it is considered to be a connected component by itself.

inputFormat

The first line contains two integers \(N\) and \(M\) where \(N\) is the number of nodes and \(M\) is the number of edges in the graph. Each of the following \(M\) lines contains two integers \(u\) and \(v\), indicating that there is an undirected edge between nodes \(u\) and \(v\).

Nodes are numbered from 1 to \(N\).

outputFormat

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

## sample
6 4
1 2
2 3
1 4
5 6
2