import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; enum mod = 10^^9 + 7; void main() { int n; scan(n); auto adj = new int[][](n, 0); foreach (i ; 0 .. n - 1) { int ui, vi; scan(ui, vi); ui--, vi--; adj[ui] ~= vi; adj[vi] ~= ui; } auto dp = new int[][](n, 2); fillAll(dp, -1); void dfs(int p, int v) { if (dp[v][0] != -1) { return; } int allDelete; dp[v][0] = 0; foreach (u ; adj[v]) { if (u == p) { continue; } dfs(v, u); allDelete += dp[u][0]; dp[v][0] += max(dp[u][0], dp[u][1]); } dp[v][1] = max(dp[v][0], allDelete + 1); } dfs(-1, 0); debug { writefln("%(%s\n%)", dp); } writeln(max(dp[0][0], dp[0][1])); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }