結果
| 問題 |
No.92 逃走経路
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2020-04-19 18:18:24 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,520 bytes |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 6,688 KB |
| 実行使用メモリ | 46,960 KB |
| 最終ジャッジ日時 | 2024-10-13 01:43:13 |
| 合計ジャッジ時間 | 2,162 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 3 WA * 5 RE * 10 |
ソースコード
function main(input) {
input = input.split("\n");
let line = input.shift().split(" ");
const n = Number(line[0]);
const k = Number(line[1]);
const m = Number(line[2]);
let list = new Array(n);
for(let i=0; i<n; i++) {
list[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]);
list[p1][p2].push(cost);
list[p2][p1].push(cost);
}
let list2 = input.shift().split(" ").map(function(e) {
return Number(e);
});
let index = 0;
let ans = [];
for(let i=0; i<n; i++) {
for(let j=0; j<n; j++) {
if(list[i][j].indexOf(list2[index]) >= 0) {
const city = walk(i, j, list, list2, index+1);
if(city >= 0) {
ans.push(city);
}
}
}
}
console.log(ans.length);
let str = "";
for(let i=0; i<ans.length; i++) {
if(i > 0) str += " ";
str += (ans[i]+1);
}
console.log(str);
}
function walk(from, to, list, list2, index) {
while(true) {
let find = false;
from = to;
for(let j=0; j<list[from].length; j++) {
const tmp = list[from][j].indexOf(list2[index]);
if(tmp < 0) continue;
find = true;
to = j;
index++;
if(index == list2.length) {
return to;
}
break;
}
if(!find) {
return -1;
}
}
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
jp_ste