結果

問題 No.92 逃走経路
ユーザー tshigtshig
提出日時 2016-08-09 12:14:16
言語 Ruby
(3.3.0)
結果
AC  
実行時間 887 ms / 5,000 ms
コード長 615 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,272 KB
実行使用メモリ 43,556 KB
最終ジャッジ日時 2023-08-27 01:42:51
合計ジャッジ時間 6,278 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
17,476 KB
testcase_01 AC 74 ms
15,236 KB
testcase_02 AC 82 ms
15,264 KB
testcase_03 AC 73 ms
15,300 KB
testcase_04 AC 80 ms
15,076 KB
testcase_05 AC 530 ms
43,076 KB
testcase_06 AC 80 ms
15,668 KB
testcase_07 AC 81 ms
15,500 KB
testcase_08 AC 77 ms
15,100 KB
testcase_09 AC 136 ms
17,472 KB
testcase_10 AC 817 ms
40,800 KB
testcase_11 AC 845 ms
43,556 KB
testcase_12 AC 887 ms
43,332 KB
testcase_13 AC 106 ms
17,096 KB
testcase_14 AC 124 ms
16,948 KB
testcase_15 AC 148 ms
17,364 KB
testcase_16 AC 134 ms
17,084 KB
testcase_17 AC 130 ms
17,376 KB
testcase_18 AC 101 ms
16,672 KB
testcase_19 AC 90 ms
15,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Calc0092
  def initialize(args)
    args = args.map { |l| l.chomp.split(/\s+/) }
    @n, @m, @k = args.shift.map(&:to_i)
    @roads = args.shift(@m).map { |l| l.map(&:to_i) }
    @ds = args.shift.map(&:to_i)
  end

  def run
    h = @roads.group_by { |r| r[2] }.map { |k, v|
      [k, v.flat_map { |w| [[w[0], w[1]], [w[1], w[0]]] }]
    }.to_h

    cands = h[@ds.shift].map(&:last).uniq
    @ds.each do |d|
      cands = h[d].select { |w| cands.include?(w.first) }.map(&:last).uniq
    end
    [cands.size, cands.sort.join(' ')].join("\n")
  end
end

puts Calc0092.new(STDIN.readlines).run if __FILE__ == $0
0