1 /**************************************************************
2 Problem: 1596
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:52 ms
7 Memory:2500 kb
8 ****************************************************************/
9
10 type
11 point=^node;
12 node=record
13 g:longint;
14 next:point;
15 end;
16 var
17 i,j,k,l,m,n:longint;
18 a:array[0..100000] of point;
19 b:array[0..100000,0..2] of longint;
20 c:array[0..100000] of longint;
21 procedure add(x,y:longint);
22 var p:point;
23 begin
24 new(p);p^.g:=y;
25 p^.next:=a[x];a[x]:=p;
26 end;
27 function min(x,y:longint):longint;
28 begin
29 if x<y then min:=x else min:=y;
30 end;
31 procedure dp(x:longint);
32 var
33 p:point;
34 a1,a2,a3,a4,a5:longint;
35 begin
36 p:=a[x];c[x]:=1;
37 a1:=0;a2:=0;
38 a3:=0;a4:=0;a5:=maxlongint;
39 while p<>nil do
40 begin
41 if c[p^.g]=0 then
42 begin
43 dp(p^.g);
44 a1:=a1+min(min(b[p^.g,0],b[p^.g,1]),b[p^.g,2]);
45 if b[p^.g,1]=maxlongint then a3:=maxlongint
46 else if a3<>maxlongint then a3:=a3+b[p^.g,1];
47 if b[p^.g,0]<=b[p^.g,1] then
48 begin
49 a4:=1;
50 a2:=a2+b[p^.g,0];
51 end
52 else
53 begin
54 a5:=min(a5,b[p^.g,0]-b[p^.g,1]);
55 a2:=a2+b[p^.g,1];
56 end;
57 end;
58 p:=p^.next;
59 end;
60 if a4=0 then a2:=a2+a5;
61 a1:=a1+1;
62 b[x,0]:=a1;b[x,1]:=a2;b[x,2]:=a3;
63 end;
64 begin
65 readln(n);
66 for i:=1 to n do a[i]:=nil;
67 for i:=1 to n-1 do
68 begin
69 readln(j,k);
70 add(j,k);add(k,j);
71 end;
72 fillchar(c,sizeof(c),0);
73 fillchar(b,sizeof(b),0);
74 dp(1);
75 writeln(min(b[1,1],b[1,0]));
76 readln;
77 end.