Help with DFS

i’ve been solving this problem for a day now https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=380
can someone pls check my code??
i did a bfs and it worked, but a dfs is not working forsomereason
my code: https://pastebin.com/HbnZdZMH