Created
October 22, 2015 16:11
-
-
Save Baekjoon/d4d31e9ad6e13a731d50 to your computer and use it in GitHub Desktop.
11403
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
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