Can anyone please tell why my code is giving SIGSEGV error for this problem even when custom input is working fine:-

Lines 73-74: you can’t say that max(a, b) or min(a, b) is the parent, you’ll end up with a really weird tree (possibly cycles, not sure) that way. The runtime error might be from an infinite loop causing a vector that’s way too big.

Compute the parents with a DFS from the root after reading in the whole tree.