結果
| 問題 |
No.763 Noelちゃんと木遊び
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-06 00:00:55 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 196 ms / 2,000 ms |
| コード長 | 837 bytes |
| コンパイル時間 | 193 ms |
| コンパイル使用メモリ | 7,452 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2025-03-22 10:36:34 |
| 合計ジャッジ時間 | 3,842 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
ソースコード
local n = io.read("*n")
local t = {}
for i = 1, n do
t[i] = {}
end
for i = 1, n - 1 do
local a, b = io.read("*n", "*n")
t[a][b] = true
t[b][a] = true
end
local function getcnt(tbl)
local c = 0
for k, v in pairs(tbl) do c = c + 1 end
return c
end
local tasks = {}
local tasknum, done = 0, 0
for i = 1, n do
if getcnt(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 dstidx, v in pairs(t[curidx]) do
for ddidx, v2 in pairs(t[dstidx]) do
t[dstidx][ddidx], t[ddidx][dstidx] = nil, nil
local c = getcnt(t[ddidx])
if c == 0 then cnt = cnt + 1
elseif c == 1 then
table.insert(tasks, ddidx)
tasknum = tasknum + 1
end
end
break
end
end
print(cnt)