Skip to content

Commit 1026eb6

Browse files
author
Eric
committed
106차 1번 문제풀이(푸는중)
1 parent 1588178 commit 1026eb6

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const n = input[0][0];
10+
const m = input[0][1];
11+
const busInfo = input.slice(2);
12+
const map = Array.from({ length: n }, () => Array(n).fill(Infinity));
13+
for (let i = 0; i < n; i++) {
14+
map[i][i] = 0;
15+
}
16+
for (const [start, end, cost] of busInfo) {
17+
map[start - 1][end - 1] = Math.min(map[start - 1][end - 1], cost);
18+
}
19+
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;
26+
if (map[i][j] > map[i][k] + map[k][j]) {
27+
map[i][j] = map[i][k] + map[k][j];
28+
}
29+
}
30+
}
31+
}
32+
}
33+
34+
console.log(solution(input));

0 commit comments

Comments
 (0)