node_count servers numbered 0 to node_count - 1. Some of them are wired together: each entry links[i] = [a, b] is a two-way cable between servers a and b.
Two servers can exchange data if there is a path of cables between them, possibly through other servers. This splits the network into groups: within a group anyone can reach anyone, while servers in different groups cannot reach each other. A server with no cables is a group of its own.
Return the number of groups.node_count=7, links=[[0, 3], [3, 5], [1, 2], [6, 4]] → 3
Servers 0, 3 and 5 form one group, 1 and 2 another, and 4 and 6 a third.
node_count=4, links=[[0, 1]] → 3
Servers 0 and 1 are linked, while 2 and 3 stand alone: three groups in total.
node_count=3, links=[[0, 1], [1, 2]] → 1
node_count ≤ 2000links.length ≤ 5000links[i].length = 2a, b < node_count, a ≠ bnode_count=7, links=[[0, 3], [3, 5], [1, 2], [6, 4]]
3
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.