Skip to content

Instantly share code, notes, and snippets.

@Baekjoon
Created October 22, 2015 16:11
Show Gist options
  • Save Baekjoon/d4d31e9ad6e13a731d50 to your computer and use it in GitHub Desktop.
Save Baekjoon/d4d31e9ad6e13a731d50 to your computer and use it in GitHub Desktop.
11403
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][]d = new int[n][n];
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
d[i][j] = sc.nextInt();
}
}
for (int k=0; k<n; k++) {
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (d[i][k] == 1 && d[k][j] == 1) {
d[i][j] = 1;
}
}
}
}
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
System.out.print(d[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment