Created
March 20, 2019 22:40
-
-
Save merciless/ac2d1630764de9e1f4984f71b0fd2718 to your computer and use it in GitHub Desktop.
Транзитивное замыкание
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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