Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 너비우선탐색
- c++
- OS
- DP
- cs
- 알고리즘
- Operating System
- 백준
- 브루트포스
- Stack
- 컴퓨터공학과
- 그래프
- 코테
- 코딩
- 정석학술정보관
- 컴공과
- 스택
- Computer science
- 구현
- 문제풀이
- 오에스
- 자료구조
- 개발
- 정석
- vector
- 오퍼레이팅시스템
- bfs
- coding
- 컴공
- 북리뷰
Archives
- Today
- Total
Little Jay
[C++] 백준 11404번 - 플로이드 본문
이름에서도 유추할 수 있듯이 플로이드 와샬 알고리즘을 쓰면 된다
#include <bits/stdc++.h>
#define endl '\n'
#define INF 987654321
using namespace std;
int table[101][101];
int n, m;
int a, b, c;
void FloydFunction(int n) {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (table[i][k] != INF || table[k][j] != INF)
table[i][j] = min(table[i][j], table[i][k] + table[k][j]);
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
cin >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
table[i][j] = INF;
}
}
for (int i = 0; i < m; i++) {
cin >> a >> b >> c;
table[a][b] = min(table[a][b], c);
}
FloydFunction(n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (table[i][j] == INF || i == j) cout << "0 ";
else cout << table[i][j] << " ";
}
cout << endl;
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 11049번 - 행렬 곱셈 순서 (0) | 2022.07.01 |
---|---|
[C++] 백준 2150번 - Strongly Connected Component (0) | 2022.07.01 |
[C++] 백준 4358번 - 생태학 (0) | 2022.06.02 |
[C++] 백준 2018번 - 수들의 합 5 (0) | 2022.05.23 |
[C++] 백준 12813번 - 이진수연산 (0) | 2022.05.22 |
Comments