Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <cassert>
- #include <vector>
- #include <algorithm>using namespace std;
- typedef vector<bool> matrix_row;
- typedef vector<matrix_row> matrix;matrix adjacency_to_incidence(const matrix &);
- void print_matrix(const matrix &);
- int main(){
- setlocale(0, "");
- const int n=6;
- bool koef[15];
- for(int i = 0;i<15;i++){
- cout << "Введiть " << i + 1 << " значення: ";
- cin >> koef[i];
- }
- int adjacencyArr[n][n];
- int k = 0;// ADJ = 0
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- adjacencyArr[i][j] = 0;
- for (int i = 0; i < n - 1; i++)
- {
- for (int j = i + 1; j < n; j++)
- if (i != j){adjacencyArr[i][j] = koef[k++];
- adjacencyArr[j][i] = adjacencyArr[i][j];
- }
- }
- matrix adj;
- for (int i = 0; i < n; i++)
- {matrix_row tmp;for (int j = 0; j < n; j++)tmp.push_back(adjacencyArr[i][j]);adj.push_back(tmp);
- }
- cout << "Матриця сумiжностi" << endl;print_matrix(adj);
- matrix inc = adjacency_to_incidence(adj);
- cout << "Матриця Iнцидентностi" << endl;
- print_matrix(inc);vector<int> adjHrom(n);
- vector<int> incHrom(n);for (int i = 0; i < n; i++)
- {
- adjHrom[i] = 0;incHrom[i] = 0;
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (adj.at(i).at(j) == 1)adjHrom[i]++;
- }
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (inc.at(i).at(j) == 1)incHrom[i]++;
- }
- }
- int maxAdjHrom = *max_element(adjHrom.begin(), adjHrom.end()) + 1, maxIncHrom =
- *max_element(incHrom.begin(),
- incHrom.end()) * 2 + 1;
- cout << "Хроматичне число " << endl;
- cout << maxAdjHrom << "\t" << maxIncHrom;_getch();
- return 0;
- matrix adjacency_to_incidence(const matrix &adj)
- {
- int cols = adj.size();
- assert(cols > 0);
- int rows = adj[0].size();
- assert(rows > 0);
- assert(rows == cols);
- int edge = 0;
- matrix incidence;
- for (int col = 0; col < cols; ++col)
- {
- for (int row = 0; row <= col; ++row) {
- if (adj[col][row])
- {
- incidence.push_back(matrix_row(cols, 0));
- incidence[edge][row] = incidence[edge][col] = 1;++edge;}
- }
- }
- return incidence;
- }
- void print_matrix(const matrix &m)
- {
- int cols = m.size();
- if (cols == 0) return;
- int rows = m[0].size();
- if (rows == 0) return;
- for (int c = 0; c < cols; ++c) {for (int r = 0; r < rows; ++r)
- {cout << m[c][r] << " ";
- }
- cout << std::endl;}cout << std::endl;
- }
- cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement