Dsa
Graphs Dfs
Easy
Computer Networks
You are given a list of computers in a network, where each computer is represented by an integer and a list of pairs indicating the direct connections between them. Write a function to find the number of distinct networks. A distinct network is defined as a group of computers that are directly or indirectly connected.
Input Format:
- The first line contains an integer n (number of computers).
- The second line contains an integer m (number of connections).
- The next m lines each contain two integers u and v, indicating a connection between computer u and computer v.
Output Format:
- Print the number of distinct networks.
Example Input:
6
4
0 1
1 2
3 4
5 5
Example Output:
3
Key concepts
graphsdfsnetwork 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