I am stumped on 29958547. What is the error in the code which hasn't been discovered till test case 15. If the entire approach is wrong, please don't reveal the the correct approach, just say that the approach is wrong. However if a silly error has been committed please point it out.
It seems to me that you are assuming x<y in edges.
Could you elaborate a little please?
You are iterating over x=2..n and assuming that parent(x) is already processed, which means that you are assuming parent(x)<x.