結果

問題 No.1244 Black Segment
ユーザー 👑 obakyanobakyan
提出日時 2022-04-25 23:49:04
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 5,284 KB
実行使用メモリ 17,208 KB
最終ジャッジ日時 2023-09-10 06:13:01
合計ジャッジ時間 7,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 86 ms
9,808 KB
testcase_15 AC 5 ms
4,380 KB
testcase_16 AC 87 ms
10,072 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 97 ms
12,312 KB
testcase_19 AC 136 ms
14,412 KB
testcase_20 AC 144 ms
14,960 KB
testcase_21 AC 119 ms
14,756 KB
testcase_22 AC 150 ms
15,336 KB
testcase_23 AC 166 ms
15,552 KB
testcase_24 AC 160 ms
16,024 KB
testcase_25 AC 155 ms
15,688 KB
testcase_26 AC 149 ms
15,564 KB
testcase_27 AC 148 ms
14,660 KB
testcase_28 AC 161 ms
16,260 KB
testcase_29 AC 145 ms
15,864 KB
testcase_30 AC 162 ms
16,028 KB
testcase_31 AC 149 ms
15,240 KB
testcase_32 AC 151 ms
15,084 KB
testcase_33 AC 151 ms
15,384 KB
testcase_34 AC 174 ms
16,136 KB
testcase_35 AC 119 ms
14,208 KB
testcase_36 AC 146 ms
14,808 KB
testcase_37 AC 166 ms
17,188 KB
testcase_38 AC 166 ms
17,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local inf = 1000000007
local n, m = io.read("*n", "*n")
local a, b = io.read("*n", "*n")
local t = {}
for i = 1, a do
  t[i] = 0
end
for i = a + 1, n + 1 do
  t[i] = inf
end
local edge = {}
for i = 1, n + 1 do
  edge[i] = {}
end
for i = 1, m do
  local l, r = io.read("*n", "*n")
  edge[l][r + 1] = true
  edge[r + 1][l] = true
end
local tasks = {}
for i = 1, a do
  tasks[i] = i
end
local done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  for dst, _u in pairs(edge[src]) do
    if 1 + t[src] < t[dst] then
      t[dst] = 1 + t[src]
      table.insert(tasks, dst)
    end
  end
end
local ret = inf
for i = b + 1, n + 1 do
  ret = mmi(ret, t[i])
end
if ret == inf then ret = -1 end
print(ret)
0