-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11403.cpp
More file actions
73 lines (52 loc) · 1.44 KB
/
11403.cpp
File metadata and controls
73 lines (52 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
11403.cpp
algo
Created by 박효정 on 2021/06/02.
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000
using namespace std;
int graph[101][101];
int main(){
cin.tie(0);
cout.tie(0);
std::ios::sync_with_stdio(false);
int n;
//입력
cin>>n;
//처음 배열의 값 INF로 초기화
for(int i=1;i<=n;i++){
fill(graph[i], graph[i]+101,INF );
}
//만약 i->j로 가는 간선이 없는 경우 INF로 초기화
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>graph[i][j];
if(graph[i][j]==0){
graph[i][j]=INF;
}
}
}
//3중 for문으로 K를 경유해 i->j로 가는 값과 비교한다.
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}
}
}
//갈수 있는 간선이 존재할 경우 해당 배열의 값이 INF가 아니고
//갈수 있는 간선이 존재하지 않을 경우 해당 배열의 값이 INF일 것 이다.
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(graph[i][j]!=INF){
cout<<1<<" ";
}
else{
cout<<0<<" ";
}
}
cout<<"\n";
}
return 0;
}