Dsa
Union Find
Warm-up
Isolated Hubs
You have a network of computers represented by unique integer IDs. Some computers are directly connected, while others are isolated. Your task is to identify how many isolated clusters of computers exist based on the connections given. A cluster is a set of computers that are all reachable from one another.
Input Format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of computers.
- The second line contains an integer m (0 ≤ m ≤ 10000), the number of direct connections between computers.
- The next m lines contain two integers a and b (1 ≤ a, b ≤ n), indicating a direct connection between computer a and computer b.
Output Format:
- Print the number of isolated clusters of computers.
Example:
Input:
4
2
1 2
3 4
Output:
2
Input:
3
0
Output:
3
Key concepts
union_findconnected_componentsgraph
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now