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)