Problem list
Log in
#r03340 · Online Judge > GoldOJ

Number of Connected Components

Silver II 2.0 s 256 MB

Given an undirected graph, print the number of connected components.

Input

First line $N$ ($1 \le N \le 1000$) and $M$ ($0 \le M \le 1000$); then $M$ lines each with an edge $u$, $v$ ($u \ne v$). Multiple edges may appear.

Output

Print the number of connected components.

Example 1

Input
6 5
1 2
2 5
5 1
3 4
4 6
Output
2

Example 2

Input
6 2
3 4
4 2
Output
4
Source
Online Judge > GoldOJ
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code