Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bogliqlik-komponentalari

Number of connected components

Easy 1000 ms 128 MB 25%
Share

An undirected graph with $n$ vertices and $m$ edges is given. The vertices are numbered from $1$ to $n$. Find the number of connected components of the graph — groups of vertices connected to each other by paths.

A graph made of two connected components

Input

The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — the vertices joined by an edge.

Output

One integer — the number of components.

Note

$1 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$
The graph may have multiple edges and loops.

Examples

Input #1
5 4
1 2
2 3
1 3
4 5
Output #1
2
Input #2
4 0
Output #2
4

Sign in to submit a solution

Signing up is free and takes a minute.