結果

問題 No.92 逃走経路
ユーザー te-shte-sh
提出日時 2017-01-27 14:10:56
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 810 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 111,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 00:55:52
合計ジャッジ時間 2,056 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 10 ms
4,376 KB
testcase_06 AC 6 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 23 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 11 ms
4,376 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.bitmanip;  // BitArray

void main()
{
  auto rd1 = readln.split.to!(size_t[]), n = rd1[0], m = rd1[1], k = rd1[2];

  int[][int][int] buf;
  foreach (_; m.iota) {
    auto rd2 = readln.split.to!(int[]), a = rd2[0] - 1, b = rd2[1] - 1, c = rd2[2];
    buf[c][a] ~= b;
    buf[c][b] ~= a;
  }

  auto di = readln.split.to!(int[]);

  auto ec = BitArray([]);
  ec.length = n;
  foreach (e; buf[di.front].keys) ec[e] = true;

  foreach (d; di.drop(1)) {
    auto en = BitArray([]);
    en.length = n;
    foreach (e; ec.bitsSet.map!(to!int))
      if (e in buf[d])
        foreach (e2; buf[d][e]) en[e2] = true;
    ec = en;
  }

  auto ri = ec.bitsSet.array;
  writeln(ri.length);
  writeln(ri.map!"a + 1".map!(to!string).join(" "));
}
0