# [BZOJ2060] [Usaco2010 Nov]Visiting Cows 拜访奶牛

### 传送门

http://www.lydsy.com/JudgeOnline/problem.php?id=2060

### 题解

var
dp:array[0..50005,0..1]of longint;
x:array[0..50005]of longint;
w:array[0..150005,1..2]of longint;
i,j,k:longint;
n,len,a,b,tt:longint;
procedure init(a,b:longint);
begin
w[len,1]:=b;
if w[a,2]=0
then w[a,2]:=len else w[w[a,1],2]:=len;
w[a,1]:=len; inc(len);
end;

function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;

procedure dfs(a:longint);
var tt:longint;
begin
x[a]:=1; tt:=w[a,2]; dp[a,1]:=1; dp[a,0]:=0;
while tt<>0 do
begin
if x[w[tt,1]]=0 then begin
dfs(w[tt,1]);
dp[a,1]:=dp[a,1]+dp[w[tt,1],0];
dp[a,0]:=dp[a,0]+max(dp[w[tt,1],1],dp[w[tt,1],0]);
end;
tt:=w[tt,2];
end;
end;

begin
for i:=1 to n-1 do
begin
init(a,b); init(b,a);
end;
dfs(1);
writeln(max(dp[1,1],dp[1,0]));
end.


#### 【BZOJ 2060】 [Usaco2010 Nov]Visiting Cows 拜访奶牛

2015-04-15 09:59:10

#### bzoj2060[USACO2010,Nov]Visiting Cows拜访奶牛

2016-10-14 22:29:17

#### bzoj2060[Usaco2010 Nov]Visiting Cows 拜访奶牛

2017-04-06 12:02:34

#### [BZOJ2060][Usaco2010 Nov]Visiting Cows 拜访奶牛

2015-10-23 22:16:59

#### bzoj2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛

2017-09-14 07:44:01

#### [BZOJ2060][Usaco2010 Nov]Visiting Cows 拜访奶牛（树形dp）

2016-04-25 21:01:29

#### bzoj 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛(树形DP)

2016-04-26 23:15:42

#### bzoj 2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛

2017-07-23 21:22:58

#### 【bzoj 2060】[Usaco2010 Nov]Visiting Cows 拜访奶牛（树形dp）

2016-05-10 14:44:22

#### bzoj 3386: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家

2017-09-25 15:06:10