Skip to content

Commit d879afe

Browse files
author
Eric
committed
106차 1번 문제풀이
1 parent 1026eb6 commit d879afe

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

live10/test106/문제1/황장현.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,28 @@ function solution(input) {
1010
const m = input[0][1];
1111
const busInfo = input.slice(2);
1212
const map = Array.from({ length: n }, () => Array(n).fill(Infinity));
13+
1314
for (let i = 0; i < n; i++) {
1415
map[i][i] = 0;
1516
}
17+
1618
for (const [start, end, cost] of busInfo) {
1719
map[start - 1][end - 1] = Math.min(map[start - 1][end - 1], cost);
1820
}
1921

20-
function backtrack() {}
21-
22-
for (let i = 0; i < n; i++) {
23-
for (let j = 0; j < n; j++) {
24-
for (let k = 0; k < n; k++) {
25-
if (i === j) continue;
22+
for (let k = 0; k < n; k++) {
23+
for (let i = 0; i < n; i++) {
24+
for (let j = 0; j < n; j++) {
2625
if (map[i][j] > map[i][k] + map[k][j]) {
2726
map[i][j] = map[i][k] + map[k][j];
2827
}
2928
}
3029
}
3130
}
31+
32+
return map
33+
.map((row) => row.map((cost) => (cost === Infinity ? 0 : cost)).join(' '))
34+
.join('\n');
3235
}
3336

3437
console.log(solution(input));

0 commit comments

Comments
 (0)