[BOJ] 11404 플로이드

Time Lapse :20min 40sec

11404.cpp

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
#include <iostream>
#include <algorithm>
#include <memory.h>
#define INF 987654321
using namespace std;
int n, m, f, e, c;
int ans[101][101];
int main() {
scanf("%d %d",&n,&m);
for(int i = 1; i <= n; i ++)
for(int j = 1; j <= n; ++j)
if(i!=j)
ans[i][j] = INF;
for(int i = 0; i < m; ++i) {
scanf("%d %d %d",&f,&e,&c);
ans[f][e] = min(ans[f][e],c);
}
for(int k = 1; k <= n; ++k)
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
ans[i][j] = min(ans[i][k] + ans[k][j], ans[i][j]);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j)
printf("%d ",ans[i][j] == INF ? 0 : ans[i][j]);
printf("\n");
}

}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/31/PS/BOJ/11404/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.