So here's the question: "There are two types of professional wrestlers: "babyfaces"("good guys") and "heels"("bad guys"). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n professional wrestlers and we have a list of r pairs of wrestlers for which there are rivalries. Give an O(n+r)-time algorithm that determines whether it is possible to designate some of the wrestlers as babyfaces and the remainder as heels such that each rivalry is between a babyface and a heel. If it is possible to perform such a designation, your algorithm should produce it."
This was on a quiz I took today. So I assumed there was some sort of trait that we would be able to use to determine whether a wrestler was a heel or babyface whenever we went over them. What I thought would work would be to create an undirected graph containing each wrestler as a connected node. The order nor do the relationships matter. Then I would Breadth-first-search through all of them. Instead of just one queue, though, I would use two. After being visited, the node would either be placed in the babyface queue or the heel queue. When both queues weren't completely empty, then I would dequeue each and pair one and one together, before going back and continuing the search.
Would this work as a solution or no?