You need to track each node's color. Create an array color of size . What values should you use?
A common choice: means uncolored (not yet visited), means first color (say, red), means second color (say, blue). Initialize all entries to . When you visit a node, set its color to or . Check if it is to know if you have seen it before. This array serves as both the color assignment and the visited tracker.