Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 103
- int n, m;
- bool a[NMAX][NMAX];
- void read() {
- cin >> n >> m;
- for (int i = 0; i < m; i++) {
- int x, y;
- cin >> x >> y;
- a[x][y] = true;
- }
- }
- void RoyWarshall() {
- for (int k = 1; k <= n; k++) {
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- if (!a[i][j]) {
- a[i][j] = a[i][k] && a[k][j];
- }
- }
- }
- }
- }
- void write() {
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= n; j++) {
- cout << a[i][j] << ' ';
- }
- cout << endl;
- }
- }
- int main() {
- read();
- RoyWarshall();
- write();
- return 0;
- }
Add Comment
Please, Sign In to add comment