whenever i use dfs or bfs following my template I get tle for example this question-https://codeforces.com/contest/1600/problem/J this is my submission- https://codeforces.com/contest/1600/submission/135985780
pls help anybody i am getting tle in O(10^6)
whenever i use dfs or bfs following my template I get tle for example this question-https://codeforces.com/contest/1600/problem/J this is my submission- https://codeforces.com/contest/1600/submission/135985780