朴素搜索
一条过了,又一道一条过的
怎么打得简洁怎么来
skysun原创,转载请注明出处,http://www.cnblogs.com/skysun
View Code
1 program sky;
2 var
3 i,j,x : longint;
4 n : longint;
5 a : array[0..1001,1..2] of longint;
6 f : array[0..1001] of longint;
7 function max(qq,ww: longint ):longint;
8 begin
9 if qq>ww then exit(qq); exit(ww);
10 end;
11 procedure dfs(x : longint );
12 begin
13 if x=0 then exit;
14 if a[x,1]<>0 then f[a[x,1]]:=f[x]+1 else f[0]:=max(f[0],f[x]+1);
15 dfs(a[x,1]);
16 if a[x,2]<>0 then f[a[x,2]]:=f[x]+1 else f[0]:=max(f[0],f[x]+1);
17 dfs(a[x,2]);
18 end;
19 begin
20 read(n);
21 for i:=1 to n-1 do
22 begin
23 read(x);
24 read(a[x,1],a[x,2]);
25 end;
26 dfs(1);
27 writeln(f[0]);
28 end.