結果

問題 No.92 逃走経路
ユーザー 👑 obakyanobakyan
提出日時 2019-05-06 09:07:09
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 175 ms / 5,000 ms
コード長 1,015 bytes
コンパイル時間 123 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 119,084 KB
最終ジャッジ日時 2023-09-09 09:28:18
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 175 ms
119,084 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,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 29 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 13 ms
4,376 KB
testcase_12 AC 29 ms
4,380 KB
testcase_13 AC 28 ms
4,376 KB
testcase_14 AC 28 ms
4,380 KB
testcase_15 AC 28 ms
4,376 KB
testcase_16 AC 29 ms
4,376 KB
testcase_17 AC 29 ms
5,272 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ior = io.input()
local n, m, k = ior:read("*n", "*n", "*n")
local matrix_list = {}

local function make_matrix()
  local tmp = {}
  for i = 1, n * n do tmp[i] = 0 end
  return tmp
end

for i = 1, m do
  local a, b, c = ior:read("*n", "*n", "*n")
  if(matrix_list[c] == nil) then
    matrix_list[c] = make_matrix()
  end
  matrix_list[c][(a - 1) * n + b] = 1
  matrix_list[c][(b - 1) * n + a] = 1
end

local vec = {}
for i = 1, n do vec[i] = 1 end
local mmi = math.min
for i_k = 1, k do
  local mat = matrix_list[ior:read("*n")]
  local ret_vec = {}
  for i = 1, n do ret_vec[i] = 0 end
  for i = 1, n do
    for j = 1, n do
      ret_vec[i] = ret_vec[i] + mat[(i - 1) * n + j] * vec[j]
    end
    ret_vec[i] = mmi(1, ret_vec[i])
  end
  vec = ret_vec
end
local cnt = 0
for i = 1, n do
  if(0 < vec[i]) then cnt = cnt + 1 end
end
print(cnt)
local fst = true
for i = 1, n do
  if(0 < vec[i]) then
    if(fst) then
      fst = false
    else
      io.write(" ")
    end
    io.write(i)
  end
end
io.write("\n")
0