Функция умножения матриц неправильно считает

Подскажите где ошибка, видимо функция умножения матриц неправильно работает скрин приложен

Что я делаю не так? Ответ умножения разумеется должен быть такой же как и матрица А

#include <iostream>
#include <algorithm>
#include <windows.h>
using namespace std;
 
class Graph {
private:
    bool** adjMatrix;
    bool** Pmatrix;
    int numVertices;
    int* p; // перестановка
public:
    Graph(int numVertices) {
        this->numVertices = numVertices;
        adjMatrix = new bool* [numVertices];
        Pmatrix = new bool* [numVertices];
        for (int i = 0; i < numVertices; i++) {
            adjMatrix[i] = new bool[numVertices];
            Pmatrix[i] = new bool[numVertices];
            for (int j = 0; j < numVertices; j++) {
                adjMatrix[i][j] = false;
                Pmatrix[i][j] = false;
            }
        }
        p = new int[numVertices];
        for (int i = 0; i < numVertices; i++)
            p[i] = i;
    }
 
    void addEdge(int i, int j) {
        adjMatrix[i][j] = true;
        adjMatrix[j][i] = true;
    }
 
    int* getP() {
        return p;
    }
 
    bool** getAdjMatrix() {
        return adjMatrix;
    }
 
    int* retPer() {
        next_permutation(p, p + numVertices);
        cout << "Перестановка" << endl;
        for (int i = 0; i < numVertices; i++)
            cout << p[i] << " ";
        cout << endl;
        return p;
    }
 
    bool** retPmatrix(int* p) {  
        for (int i = 0; i < numVertices; i++)
            for (int j = 0; j < numVertices; j++)
                Pmatrix[i][j] = false;
        for (int i = 0; i < numVertices; i++)
            Pmatrix[p[i]][i] = true;
        return Pmatrix;
    }
 
    bool** traspPmatrix(bool** Pmatrix) {
        bool** tPmatrix = new bool* [numVertices];
        for (int i = 0; i < numVertices; i++) {
            tPmatrix[i] = new bool[numVertices];
            for (int j = 0; j < numVertices; j++)
                tPmatrix[i][j] = Pmatrix[j][i];
        }
        return tPmatrix;
    }
 
    bool** mulMatrix(bool** A, bool** B) {
        bool** C = new bool* [numVertices];
        int i, j, k;
        for (i = 0; i < numVertices; i++) {
            C[i] = new bool[numVertices];
            for (j = 0; j < numVertices; j++)
                for (k = 0; k < numVertices; k++)
                    C[i][j] += A[i][k] * B[k][j];
        }
        return C;
    }
 
    void printMatrix(bool** Matrix) {
        for (int i = 0; i < numVertices; i++) {
            cout << i << " : ";
            for (int j = 0; j < numVertices; j++)
                cout << Matrix[i][j] << " ";
            cout << endl;
        }
        cout << endl;
    }
 
    ~Graph() {
        for (int i = 0; i < numVertices; i++)
            delete[] adjMatrix[i];
        delete[] adjMatrix;
    }
};
 
int main() {
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    Graph g1(4);
    //GRAPH1////////
    g1.addEdge(0, 1);
    g1.addEdge(0, 2);
    g1.addEdge(1, 2);
    g1.addEdge(2, 3);
    cout << "Матрица смежности графа А" << endl;
    g1.printMatrix(g1.getAdjMatrix());
    cout << "Матрица перестановки P" << endl;
    g1.printMatrix(g1.retPmatrix(g1.getP()));
    cout << "Умножение PA" << endl;
    g1.printMatrix(g1.mulMatrix(g1.retPmatrix(g1.getP()), g1.getAdjMatrix()));
}

Ответы (0 шт):