結果
問題 |
No.763 Noelちゃんと木遊び
|
ユーザー |
👑 |
提出日時 | 2019-06-05 23:44:34 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,007 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 16,128 KB |
最終ジャッジ日時 | 2024-09-22 13:29:02 |
合計ジャッジ時間 | 3,917 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 21 |
ソースコード
local n = io.read("*n") local t = {} local removed = {} for i = 1, n do t[i] = {} removed[i] = false end for i = 1, n - 1 do local a, b = io.read("*n", "*n") table.insert(t[a], b) table.insert(t[b], a) end local tasks = {} local tasknum, done = 0, 0 for i = 1, n do if #t[i] == 1 then tasknum = tasknum + 1 table.insert(tasks, i) end end local cnt = 0 while done < tasknum do done = done + 1 local curidx = tasks[done] for i = 1, #t[curidx] do local dstidx = t[curidx][i] if not removed[dstidx] then removed[dstidx] = true for j = 1, #t[dstidx] do local dstdstidx = t[dstidx][j] local tmp = 0 for k = 1, #t[dstdstidx] do local dddidx = t[dstdstidx][k] if not removed[dddidx] then tmp = tmp + 1 end end if tmp == 0 then cnt = cnt + 1 elseif tmp == 1 then tasknum = tasknum + 1 table.insert(tasks, dstdstidx) end end break end end end print(cnt)