In one of the test cases in Neighbours of node in Trees and Binary trees my solution didn’t work and with debugging I found a problem with the failed test case itself.
The test file contained two lines:
|
Line 25602: 63495 85001 |
|
Line 27819: 61777 85001 |
This can’t be a “tree”

Additional info
Hey @samehragheb , actually there’s an error in your code. You’re treating the structure as a directed graph or tree, but this is an undirected tree, which means the connection between u and v is bidirectional. Just because u is connected to v doesn’t mean u is the parent of v. That’s why your code is giving an error.
Yes, a node in a tree can’t have two parents, but in this test case, we don’t know which one is the parent of node 85001. All we know is that 5 nodes are connected to 85001.