Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 560 Bytes

File metadata and controls

9 lines (5 loc) · 560 Bytes

Solution

Represent this as a Graph. Names are Nodes. Pairs of names are Edges.

Generating the desired output is simply doing a BFS or DFS on each connected component, while summing the values at each node.

Time/Space Complexity

Same as BFS or DFS, depending on which was used