Problem hidden
CCOMPS - Count Components
Given an undirected graph of N nodes (numbered from 1 to N) and M edges,
find the number of its connected components.
Given an undirected graph of N nodes (numbered from 1 to N) and M edges, find the number of its connected components.
Input
The first line of input consists of two integers, N and M, the number of nodes and the number of edges respectively. (N ≤ 100000, M ≤ 200000)
The next M lines of input contain a pair of integers (x, y) representing anedge between nodes x and y. (1 ≤ x, y ≤ N)
Output
To the first and only line of output, print a single integer: the number of connected components.
Example
Input: 5 2 1 2 3 4
Output: 3
Added by: | gustav |
Date: | 2014-12-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | classical problem |