Dsa
Union Find
Easy
Network Connection
You are managing a computer network represented by connections between computers. Each computer is identified by an integer. Given a list of connections, write a program to determine if all computers are connected directly or indirectly. If they are connected, output 'Connected'. Otherwise, output 'Not Connected'.
Input:
The first line contains an integer n (1 <= n <= 1000), the number of connections. The next n lines contain two integers a and b (0 <= a, b <= 999), indicating a connection between computer a and computer b.
Output:
Print 'Connected' if all computers are connected, otherwise print 'Not Connected'.
Example:
Input:
4
0 1
0 2
1 2
3 4
Output:
Not Connected
Key concepts
union_findnetworkingdynamic connectivity
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