結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー 👑 obakyanobakyan
提出日時 2021-06-10 21:02:45
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 519 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 39,056 KB
最終ジャッジ日時 2023-08-20 07:17:21
合計ジャッジ時間 8,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 519 ms
38,796 KB
testcase_25 AC 519 ms
39,004 KB
testcase_26 AC 515 ms
38,996 KB
testcase_27 AC 514 ms
38,980 KB
testcase_28 AC 516 ms
39,016 KB
testcase_29 AC 508 ms
39,056 KB
testcase_30 AC 511 ms
38,948 KB
testcase_31 AC 509 ms
38,964 KB
testcase_32 AC 510 ms
38,908 KB
testcase_33 AC 510 ms
39,020 KB
testcase_34 AC 160 ms
29,180 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local n, m = io.read("*n", "*n")
local edge = {}
local invedge = {}
local lrem, rrem = {}, {}
local llen, rlen = {}, {}
for i = 1, n do
  edge[i], invedge[i] = {}, {}
  lrem[i], rrem[i] = 0, 0
  llen[i], rlen[i] = 0, 0
end
for i = 1, m do
  local a, b, c = io.read("*n", "*n", "*n")
  a, b = a + 1, b + 1
  edge[a][b], invedge[b][a] = c, c
  lrem[b] = lrem[b] + 1
  rrem[a] = rrem[a] + 1
end
local tasks = {}
for i = 1, n do
  if lrem[i] == 0 then table.insert(tasks, i) end
end
for i = 1, n do
  local src = tasks[i]
  for dst, cost in pairs(edge[src]) do
    llen[dst] = mma(llen[dst] ,llen[src] + cost)
    lrem[dst] = lrem[dst] - 1
    if lrem[dst] == 0 then
      table.insert(tasks, dst)
    end
  end
end
local totlen = llen[n]
tasks = {}
for i = 1, n do
  if rrem[i] == 0 then table.insert(tasks, i) end
end
local denom = n
local numer = n
for i = 1, n do
  local src = tasks[i]
  if rlen[src] + llen[src] == totlen then
    numer = numer - 1
  end
  for dst, cost in pairs(invedge[src]) do
    rlen[dst] = mma(rlen[dst], rlen[src] + cost)
    rrem[dst] = rrem[dst] - 1
    if rrem[dst] == 0 then
      table.insert(tasks, dst)
    end
  end
end

local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
print(totlen .. " " .. numer .. "/" .. denom)
0