結果
問題 | No.1817 Reversed Edges |
ユーザー | obakyan |
提出日時 | 2022-01-22 15:29:24 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 1,475 bytes |
コンパイル時間 | 341 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 24,192 KB |
最終ジャッジ日時 | 2024-05-05 14:41:11 |
合計ジャッジ時間 | 5,012 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 156 ms
22,528 KB |
testcase_08 | AC | 63 ms
12,544 KB |
testcase_09 | AC | 131 ms
22,016 KB |
testcase_10 | AC | 70 ms
13,184 KB |
testcase_11 | AC | 93 ms
14,848 KB |
testcase_12 | AC | 158 ms
24,064 KB |
testcase_13 | AC | 166 ms
24,064 KB |
testcase_14 | AC | 169 ms
23,936 KB |
testcase_15 | AC | 167 ms
24,192 KB |
testcase_16 | AC | 169 ms
24,064 KB |
testcase_17 | AC | 164 ms
24,064 KB |
testcase_18 | AC | 157 ms
24,064 KB |
testcase_19 | AC | 162 ms
24,064 KB |
testcase_20 | AC | 162 ms
24,064 KB |
testcase_21 | AC | 161 ms
24,064 KB |
testcase_22 | AC | 92 ms
23,552 KB |
testcase_23 | AC | 88 ms
23,424 KB |
testcase_24 | AC | 88 ms
23,296 KB |
ソースコード
local n = io.read("*n") local a, b = {}, {} local edge = {} local parent = {} local ccnt, w, score = {}, {}, {} for i = 1, n do edge[i] = {} parent[i] = 0 ccnt[i] = 0 w[i] = 1 score[i] = 0 end for i = 1, n - 1 do a[i], b[i] = io.read("*n", "*n") table.insert(edge[a[i]], i) table.insert(edge[b[i]], i) end local tasks = {1} for i = 1, n do local src = tasks[i] for j = 1, #edge[src] do local ej = edge[src][j] local dst = a[ej] + b[ej] - src if parent[src] ~= dst then table.insert(tasks, dst) parent[dst] = src ccnt[src] = ccnt[src] + 1 end end end local t2 = {} for i = 1, n do if ccnt[i] == 0 then table.insert(t2, i) end end local bias = 0 for i = 1, n do local src = t2[i] for j = 1, #edge[src] do local ej = edge[src][j] local dst = a[ej] + b[ej] - src if parent[src] == dst then w[dst] = w[dst] + w[src] if src < dst then bias = bias + 1 score[src] = score[src] - 1 else score[src] = score[src] + 1 end ccnt[dst] = ccnt[dst] - 1 if ccnt[dst] == 0 then table.insert(t2, dst) end break end end end for i = 1, n do local src = tasks[i] for j = 1, #edge[src] do local ej = edge[src][j] local dst = a[ej] + b[ej] - src if parent[src] ~= dst then score[dst] = score[dst] + score[src] end end end for i = 1, n do score[i] = score[i] + bias end print(table.concat(score, "\n"))