Help in QTREE SPOJ

Can someone help me with this code please… this code was written by me for solving QTREE SPOJ problem using Heavy Light Decomposition and it is getting Runtime error SIGSEGV.

Here is the link to the code and self-made test case: k3JAze - Online C++ Compiler & Debugging Tool - Ideone.com