結果

問題 No.92 逃走経路
ユーザー te-shte-sh
提出日時 2016-08-30 14:22:39
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 124,400 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 21:35:47
合計ジャッジ時間 2,100 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range;
import std.string, std.conv;
import std.math, std.bigint, std.bitmanip, std.random;
import std.stdio, std.typecons;

alias Tuple!(int, "n1", int, "n2") side;

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

  side[][int] si;
  foreach (_; 0..m) {
    auto rd2 = readln.split.map!(to!int);
    si[rd2[2]] ~= side(rd2[0] - 1, rd2[1] - 1);
  }

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

  auto cands = BitArray([]);
  cands.length = n;

  foreach (s; si[di[0]]) {
    cands[s.n1] = true;
    cands[s.n2] = true;
  }

  foreach (i; 1..k) {
    auto next = BitArray([]);
    next.length = n;
    foreach (s; si[di[i]]) {
      if (cands[s.n1])
        next[s.n2] = true;
      if (cands[s.n2])
        next[s.n1] = true;
    }
    cands = next;
  }

  auto r = cands.bitsSet.array;
  writeln(r.length);
  writeln(r.map!(x => x + 1).map!(to!string).join(' '));
}
0