Help with error

sol: https://ide.codingblocks.com/s/421518

prob: https://hack.codingblocks.com/app/contests/2022/1881/problem

idea which I have implemented:
create a path from the given nodes store it in a vector,
iterate the vector when you find the lca start take 2 counters x and y and keep incrementing them for the remaining lengths of the vector and return x+y

not working correctly

Approach is correct
but you have done some mistakes while implementing the approach
i have correct all the mistakes

if you have doubt in any line feel free to ask

Modified Code