Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- enum boxer_colour // the colour
- {
- UNDEFINED, // non-visited
- RED,
- BLUE
- };
- struct boxer // a boxer point
- {
- boxer_colour colour;
- vector <int> boxing_with;
- boxer()
- {
- colour = UNDEFINED;
- return;
- }
- };
- boxer_colour opposite(boxer_colour c)
- {
- switch (c)
- {
- case RED:
- return BLUE;
- case BLUE:
- return RED;
- case UNDEFINED:
- return UNDEFINED;
- default:
- return UNDEFINED;
- }
- }
- int main()
- {
- int boxers_count, edges; // size of boxers array
- cin >> boxers_count >> edges;
- vector <boxer> boxers(boxers_count); // boxers
- for (int i = 0; i < edges; i++) // input edges
- {
- int a, b;
- cin >> a >> b;
- boxers[a].boxing_with.push_back(b);
- boxers[b].boxing_with.push_back(a);
- }
- queue <int> bfs_queue; // BFS queue
- bfs_queue.push(0); // add boxer 0 to BFS queue
- boxers[0].colour = RED;
- while (!bfs_queue.empty()) // BFS
- {
- int boxer_index = bfs_queue.front(); // get check index for boxer
- bfs_queue.pop();
- for (int i = 0; i < boxers[boxer_index].boxing_with.size(); i++) // check all edges connecting to boxer
- {
- if (boxers[boxers[boxer_index].boxing_with[i]].colour == boxers[boxer_index].colour)
- {
- cout << "NE"; // two neighbour boxers have same pants colour
- return 0;
- }
- if (boxers[boxers[boxer_index].boxing_with[i]].colour == UNDEFINED)
- {
- boxers[boxers[boxer_index].boxing_with[i]].colour = opposite(boxers[boxer_index].colour);
- bfs_queue.push(boxers[boxer_index].boxing_with[i]); // colour with opposite colour
- }
- }
- }
- cout << "DA"; // all pants are given
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement