일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- photon fusion2
- gas
- 게임개발
- 메카님
- Unreal Engine
- MAC
- unity
- Aegis
- animation
- CTF
- DSP
- gameplay effect
- MLFQ
- 유니티
- Delegate
- ret2libc
- 유스케이스
- Replication
- map design
- Race condition
- dirty cow
- stride
- 게임 개발
- 언리얼 엔진
- Multiplay
- gameplay ability system
- ability task
- 언리얼엔진
- Security
- gravity direction
Archives
- Today
- Total
Replicated
[DP] 플로이드 워셜 최단거리 본문
https://www.acmicpc.net/problem/11404
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m;
cin >> n >> m;
// init
int arr[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if( i == j ) arr[i][j] = 0;
else arr[i][j] = -1;
}
}
// input
for (int i = 0; i < m; ++i) {
int row, col, weight;
cin >> row >> col >> weight;
if( arr[row - 1][col - 1] < 0 || arr[row - 1][col - 1] > weight ){
arr[row - 1][col - 1] = weight;
}
}
for (int k = 0; k < n; ++k) {
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; ++i) {
if( arr[i][k] == -1 || arr[k][j] == -1 ) continue;
if( arr[i][k] + arr[k][j] < arr[i][j] || arr[i][j] == -1 ) {
arr[i][j] = arr[i][k] + arr[k][j];
}
}
}
}
for (int i = 0; i < n; ++i) {
if( i > 0 ) cout << '\n';
for (int j = 0; j < n; ++j) {
if( arr[i][j] == - 1 ) arr[i][j] = 0;
if( j > 0 ) cout << " ";
cout << arr[i][j];
}
}
return 0;
}
모든 노드 간 최단 경로 구하기
중간 노드를 설정함 (k)
-1이면 거리가 무한
'알고리즘' 카테고리의 다른 글
[DP] 벨만 포드 최단 거리 (0) | 2024.11.05 |
---|---|
[DP] 비트마스킹 외판원 순회 (0) | 2024.11.04 |
[Greedy] 다익스트라 최단 경로 (0) | 2024.11.03 |
[DP] 최대/최소 KnapSack (0) | 2024.11.01 |