Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #define push_back pb
- #include <string>
- #include <vector>
- #include <iostream>
- using namespace std;
- vector<int> g[1005];
- int colour[1005];
- int visited[1005];
- int a = -1;
- bool wrong = 0;
- void dfs(int a) {
- visited[a] = 1;
- for (int i=0; i < g[a].size(); i++) {
- if (visited[g[a][i]] == 0) {
- colour[g[a][i]] = 1 - colour[a];
- dfs(g[a][i]);
- }
- else {
- if (colour[g[a][i]] == colour[a]) {
- wrong = 1;
- }
- }
- }
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- while (a != 0) {
- wrong = 0;
- for (int i=0; i < 1005; i++) {
- visited[i] = 0;
- colour[i] = 0;
- }
- cin >> a;
- if (a != 0) {
- int b;
- cin >> b;
- for (int i=1; i < a+1; i++) {
- g[i].clear();
- }
- for (int i=0; i<b; i++) {
- int x, y;
- cin >> x >> y;
- g[x].pb(y);
- g[y].pb(x);
- }
- dfs(1);
- if (wrong) {
- cout << "NOT BICOLOURABLE." << endl;
- }
- else {
- cout << "BICOLOURABLE." << endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment