import std.stdio, std.conv, std.string, std.bigint; import std.math, std.random, std.datetime; import std.array, std.range, std.algorithm, std.container, std.format; string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; } class Node{ int id; Node parent; Node[] nodes; Node[] kids; int ans1, ans2; // ans1は自分が除去された時、ans2は自分が除去されない時 this(int id){ this.id = id; } override string toString(){ return "#" ~ this.id.to!string ~ "(" ~ (this.parent? this.parent.id.to!string: "*") ~ ") (" ~ this.kids.map!(x => x.id.to!string).array.join(", ") ~ ") " ~ ans1.to!string ~ " " ~ ans2.to!string; } void setKids(){ foreach(nd; this.nodes){ if(this.parent && this.parent.id == nd.id) continue; if(nd.parent) continue; this.kids ~= nd; nd.parent = this; nd.setKids(); } } void solve(){ this.ans1 = 0, this.ans2 = 1; foreach(kid; this.kids){ kid.solve; this.ans1 += max(kid.ans1, kid.ans2); this.ans2 += max(kid.ans1, kid.ans2 - 1); } } } void main(){ int n = read.to!int; Node[] nodes; foreach(i; 0 .. n) nodes ~= new Node(i); foreach(i; 0 .. n - 1){ int u = read.to!int - 1, v = read.to!int - 1; nodes[u].nodes ~= nodes[v]; nodes[v].nodes ~= nodes[u]; } nodes[0].setKids; debug foreach(nd; nodes) nd.writeln; nodes[0].solve; debug foreach(nd; nodes) nd.writeln; max(nodes[0].ans1, nodes[0].ans2).writeln; }