Problem · Graph
Connected Sum
Learn this problemProblem statement
Given an undirected graph with nodes 1 through n, find every connected-component size. Return the sum of ceil(sqrt(size)) over all components.
Function
connectedSum(n: int, graphFrom: int[], graphTo: int[]) → intExamples
Example 1
n = 6graphFrom = [1,2,4]graphTo = [2,3,5]return = 5Component sizes are 3, 2, and 1, contributing 2 + 2 + 1.
Constraints
1 <= n <= 200000- Edges join valid distinct node IDs.