Loading...
Loading...
Loading...
A company has n offices numbered 1 to n and m cables. A cable "a b" links offices a and b in both directions. Offices that can reach each other through cables form one network. Print the number of networks.
Example 1
Input
6 3 1 2 2 3 4 5
Output
3
Networks are {1, 2, 3}, {4, 5} and {6}.
Example 2
Input
3 3 1 2 2 3 3 1
Output
1
Try the problem first. Open one hint at a time.
Start with n separate groups.
Each cable that joins two different groups lowers the count by one.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor