Loading...
Loading...
Loading...
A company has n computers and m two-way cables. Computers that can reach each other through cables form one network. Print how many separate networks there are. A computer with no cable is a network of its own.
Example 1
Input
6 3 0 1 1 2 3 4
Output
3
Example 2
Input
3 0
Output
3
Try the problem first. Open one hint at a time.
Go through the nodes in order. Start a search at every node you have not seen.
Add one for each start.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor