728x90
반응형
https://www.acmicpc.net/problem/1719
1719번: 택배
명우기업은 2008년부터 택배 사업을 새로이 시작하기로 하였다. 우선 택배 화물을 모아서 처리하는 집하장을 몇 개 마련했지만, 택배 화물이 각 집하장들 사이를 오갈 때 어떤 경로를 거쳐야 하
www.acmicpc.net
#include <iostream>
#define INF 987654321
using namespace std;
int n, m;
int graph[201][201];
int answer[201][201];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i == j) graph[i][j] = 0;
else graph[i][j] = INF;
}
}
for(int i = 0; i < m; i++){
int from, to, dis;
cin >> from >> to >> dis;
graph[from][to] = dis;
graph[to][from] = dis;
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
answer[i][j] = j;
}
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(graph[i][k] + graph[k][j] < graph[i][j]){
graph[i][j] = graph[i][k] + graph[k][j];
answer[i][j] = answer[i][k];
}
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i == j) cout << "-" << " ";
else cout << answer[i][j] << " ";
}
cout << endl;
}
return 0;
}
728x90
반응형
'Algorithm > BAEKJOON' 카테고리의 다른 글
[BOJ] 1916번 최소비용 구하기 (C++) (0) | 2022.05.06 |
---|---|
[BOJ] 1240번 노드사이의 거리 (C++) (0) | 2022.05.05 |
[BOJ] 11404번 플로이드 (C++) (0) | 2022.05.04 |
[BOJ] 14938번 서강그라운드 (C++) (0) | 2022.05.04 |
[BOJ] 23843번 콘센트 (C++) (0) | 2022.05.01 |