-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11403.js
More file actions
28 lines (25 loc) · 872 Bytes
/
11403.js
File metadata and controls
28 lines (25 loc) · 872 Bytes
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
/*
플로이드-워셜
근데 비용은 따지지 않는
opt(a, b):= a에서 b로 가는 길이 있는지
opt(a, b) = opt(a, b) or (opt(a, k) and opt(k, b))
단, k는 a와 b가 아닌 임의의 점
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const [[vertexCount], ...adjMatrix] = require('fs')
.readFileSync(INPUT_FILE)
.toString()
.trim()
.split('\n')
.map((line) => line.split(' ').map(Number));
const opt = Array.from({ length: vertexCount }, (_, row) =>
Array.from({ length: vertexCount }, (_, col) => adjMatrix[row][col]),
);
for (let mid = 0; mid < vertexCount; mid += 1) {
for (let start = 0; start < vertexCount; start += 1) {
for (let end = 0; end < vertexCount; end += 1) {
opt[start][end] ||= opt[start][mid] && opt[mid][end];
}
}
}
console.log(opt.map((row) => row.join(' ')).join('\n'));