Skip to content

Instantly share code, notes, and snippets.

@merciless
Created March 20, 2019 22:40
Show Gist options
  • Save merciless/ac2d1630764de9e1f4984f71b0fd2718 to your computer and use it in GitHub Desktop.
Save merciless/ac2d1630764de9e1f4984f71b0fd2718 to your computer and use it in GitHub Desktop.
Транзитивное замыкание
#include "iostream"
using namespace std;
int main() {
int n;
cin >> n;
int val;
bool matrix[100][100]{};
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> val;
matrix[i][j] = val;
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
matrix[i][j] = matrix[i][j] || (matrix[i][k] && matrix[k][j]);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << matrix[i][j] << " ";
}
cout << "\n";
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment