Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Graph
- {
- int n, colors, *paint_current, to_check;
- bool **arr;
- public:
- Graph(int x, bool **matrix, int a)
- {
- colors = 1;
- to_check = a;
- n = x;
- arr = matrix;
- paint_current = new int[n]{0};
- }
- void check_color();
- void painting();
- bool check();
- };
- bool Graph::check()
- {
- bool x = true;
- for (int i = 0; i < n; i++)
- if (paint_current[i] == 0)
- x = false;
- return x;
- }
- void Graph::painting()
- {
- int current_v = 0, current_plus = 0;
- while(!check())
- {
- for (int i = 0; i < n; i++)
- if (paint_current[i] == 0)
- {
- current_v = i;
- paint_current[current_v] = colors;
- colors++;
- break;
- }
- int j = 0;
- while (j < n)
- {
- if (arr[current_v][j] == 0 && paint_current[j] == 0)
- {
- current_plus = j;
- for (int i = 0; i < n; i++)
- arr[current_v][i] += arr[current_plus][i];
- paint_current[current_plus] = paint_current[current_v];
- }
- j++;
- }
- }
- colors--;
- check_color();
- }
- void Graph::check_color()
- {
- if (colors <= to_check)
- cout << "YES";
- else cout << "NO";
- }
- int main()
- {
- int n, colors;
- cin >> n >> colors;
- bool **arr= new bool*[n];
- for (int i= 0; i< n; i++)
- arr[i] = new bool[n];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- cin >> arr[i][j];
- if ( i== j)
- arr[i][j] = 1;
- }
- Graph object(n, arr, colors);
- object.painting();
- }
Add Comment
Please, Sign In to add comment