记录编号 | 42216 | 评测结果 | AAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 1071.[USACO Oct09] 悠闲的漫步 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.005 s | ||
提交时间 | 2012-09-17 19:50:09 | 内存使用 | 0.32 MiB | ||
#include<fstream> using namespace std; ifstream fi("stroll.in"); ofstream fo("stroll.out"); void dfs(int,int); int p,r[1001]={-1},l[1001]={-1},m=0; int main() { int a,b,c,i; fi>>p; for(i=1;i<p;i++) { fi>>a>>b>>c; r[a]=b;l[a]=c; } dfs(1,0); fo<<m; return 0; } void dfs(int step,int max) { if(r[step]==0&&l[step]==0) { if(max+1>m) { m=max+1; } } if(r[step]!=0) { dfs(r[step],max+1); } if(l[step]!=0) { dfs(l[step],max+1); } }