結果
問題 | No.92 逃走経路 |
ユーザー |
![]() |
提出日時 | 2020-04-20 07:17:23 |
言語 | JavaScript (node v23.5.0) |
結果 |
AC
|
実行時間 | 348 ms / 5,000 ms |
コード長 | 1,453 bytes |
コンパイル時間 | 63 ms |
コンパイル使用メモリ | 6,692 KB |
実行使用メモリ | 48,128 KB |
最終ジャッジ日時 | 2024-10-13 01:43:22 |
合計ジャッジ時間 | 4,038 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
function main(input) {input = input.split("\n");let line = input.shift().split(" ");const n = Number(line[0]);const m = Number(line[1]);const k = Number(line[2]);let mList = new Array(n);for(let i=0; i<n; i++) {mList[i] = new Array(n).fill().map(function(e){return [];});}for(let i=0; i<m; i++) {line = input.shift().split(" ");const p1 = Number(line[0]) - 1;const p2 = Number(line[1]) - 1;const cost = Number(line[2]);mList[p1][p2].push(cost);mList[p2][p1].push(cost);}let kList = input.shift().split(" ").map(function(e) {return Number(e);});let ansSet = new Set();for(let i=0; i<n; i++) {for(let j=0; j<n; j++) {const index = mList[i][j].indexOf(kList[0]);if(index >= 0) {ansSet.add(j);}}}for(let i=1; i<k; i++) {const nextK = kList[i];let nextAnsSet = new Set();ansSet.forEach(function(from) {for(let to=0; to<n; to++) {const index = mList[from][to].indexOf(nextK);if(index >= 0) {nextAnsSet.add(to);}}});ansSet = nextAnsSet;}const ansList = Array.from(ansSet).sort(function(a, b) {return a - b;});console.log(ansList.length);let str = "";ansList.forEach(function(e, i) {if(i > 0) str += " ";str += (e+1);});console.log(str);}main(require("fs").readFileSync("/dev/stdin", "utf8"));