I used two DFS to approach the solution. But I'm getting run time error. Can anyone help me with this? Link to the problem asked 16 Feb, 20:18

Your solution is accepted after correcting some logical error. there were some logical errors in your solution which were giving Segfault.
Here dist is an integer pointer so sizeof(dist) will give either $8$ byte or $4$ byte depending on architecture. So the line
is making all the worst. Because it is setting only first 4 or 8 bytes as 1 but the array size is larger than this. Now if you replace this with
then this will work. Edited code link LongestPathCorrected answered 17 Feb, 15:05
Thanks @brij_raj
(18 Feb, 11:48)
