• + 0 comments

    Tough one. DFS for depth building, LCA for path finding (using depth), trying to put node with most connections at the root of the tree, simple math for sums (will fit in normal int), optimized visited nodes storage. Tried caching paths (no improvement). Still getting 8 timeouts (TCs: 5,6,8,9,11,14,15,17) :(

    Undoubtedly there's another algo or structure I need to use.