結果

問題 No.763 Noelちゃんと木遊び
ユーザー 👑 obakyanobakyan
提出日時 2019-06-05 23:44:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 5,252 KB
実行使用メモリ 16,080 KB
最終ジャッジ日時 2023-10-23 19:46:39
合計ジャッジ時間 5,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0