TLE in testcases 2 & 3 in Color The graph Problem on HackerEarth

When the value of vertices is 1000000 and edges is 2000000, my code gives TLE.
How can this be rectified?

you can start coloring from node 1 and see if there is a odd length cycle in the graph , then print No else keep printing it, it can be done in 1 dfs only , time complexity is O(n) ,
try it again , for the solution , let me know again