code for DRHTS works correctly for 5000 vertices, but gives WA at codechef

i worked a lot on this code of mine(prob statement http://www.codechef.com/problems/DRGHTS) bt couldnt find the bug…
then i wrote a generator file and got a valid test case of 50, 100 and then 5000 vertices.
then i compared my codes o/p with that of one which was ACCEPTED at codechef…
both codes give exactly same op, wht should i do??
i am new to coding, and i guess it could be some silly mistake like nt taking long long to prevent overflow…please help guys i have spent a lot of time on this.i request jst spare a minute find if thres a syntax eror of that sort.
heres the comparision :
50 vertices :
ACC : http://ideone.com/Vl6ch6
mine : http://ideone.com/Ku1lll

100 vertices :
ACC : http://ideone.com/jMxdOQ
mine : http://ideone.com/IYPIzo

5000 vertices :
ACC : http://ideone.com/DRheT5
mine : http://ideone.com/d6YmAP

//