結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | 👑 obakyan |
提出日時 | 2019-07-18 22:58:36 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 1,564 bytes |
コンパイル時間 | 36 ms |
コンパイル使用メモリ | 6,692 KB |
実行使用メモリ | 25,216 KB |
最終ジャッジ日時 | 2024-06-07 16:06:14 |
合計ジャッジ時間 | 4,252 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 30 ms
6,944 KB |
testcase_14 | AC | 54 ms
7,808 KB |
testcase_15 | AC | 36 ms
6,940 KB |
testcase_16 | AC | 119 ms
11,904 KB |
testcase_17 | AC | 280 ms
23,296 KB |
testcase_18 | AC | 347 ms
24,320 KB |
testcase_19 | AC | 375 ms
25,216 KB |
testcase_20 | AC | 310 ms
23,040 KB |
testcase_21 | AC | 315 ms
24,192 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
testcase_25 | AC | 269 ms
23,808 KB |
testcase_26 | AC | 294 ms
25,216 KB |
testcase_27 | AC | 323 ms
25,216 KB |
testcase_28 | AC | 236 ms
18,944 KB |
ソースコード
local function uf_initialize(n) local parent = {} for i = 1, n do parent[i] = i end return parent end local function uf_findroot(idx, parent) while parent[idx] ~= idx do idx = parent[idx] end return idx end local function kruskal(parent, line, force) -- line.c, line.i1, line.i2 table.sort(line, function(a, b) return a.c < b.c end) local totalcost = 0 local linenum = #line for i = 1, linenum do local c, i1, i2 = line[i].c, line[i].i1, line[i].i2 local r1, r2 = uf_findroot(i1, parent), uf_findroot(i2, parent) parent[i1], parent[i2] = r1, r2 if force or r1 ~= r2 then parent[r2] = r1 parent[i2] = r1 totalcost = totalcost + c end end return totalcost end local n, m, k = io.read("*n", "*n", "*n") local a, b, c = {}, {}, {} local allcost = 0 for i = 1, m do a[i], b[i], c[i] = io.read("*n", "*n", "*n") allcost = allcost + c[i] end local curpos = 1 local forceline, line = {}, {} for i = 1, k do local e = io.read("*n") for j = curpos, e - 1 do local tmp = {} tmp.i1, tmp.i2, tmp.c = a[j], b[j], c[j] table.insert(line, tmp) end local tmp2 = {} tmp2.i1, tmp2.i2, tmp2.c = a[e], b[e], c[e] table.insert(forceline, tmp2) curpos = e + 1 end for i = curpos, m do local tmp = {} tmp.i1, tmp.i2, tmp.c = a[i], b[i], c[i] table.insert(line, tmp) end local parent = uf_initialize(n) local cost = 0 if 0 < #forceline then cost = cost + kruskal(parent, forceline, true) end if 0 < #line then cost = cost + kruskal(parent, line, false) end print(allcost - cost)