Graph is a tree or not using BFS

My code giving incorrect output plz make corrections:

Hello @coderajay03 your doubt is not in my portal you can raise the doubt again someother TA will answer your doubt.