记录编号 |
205540 |
评测结果 |
AAAAAAAAAA |
题目名称 |
不平凡的许愿树 |
最终得分 |
100 |
用户昵称 |
Derrick_M |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
3.686 s |
提交时间 |
2015-11-05 15:47:43 |
内存使用 |
0.34 MiB |
显示代码纯文本
program P2096;
type
roads=record
toit,next:longint;
end;
const
mo=338;
var
ans1,ans2,n,i,u,v,cnt,max:longint;
flag:array[1..5000] of boolean;
deep,f1,f2,f3,list:array[1..5000] of longint;
road:array[1..10010] of roads;
procedure add(u,v:longint);
begin
inc(cnt);
road[cnt].toit:=v;
road[cnt].next:=list[u];
list[u]:=cnt;
end;
procedure dfs(u:longint);
var
v,w:longint;
begin
w:=list[u];
flag[u]:=true;
while w<>0 do
begin
v:=road[w].toit;
if not flag[v] then
begin
deep[v]:=deep[u]+1;
if deep[v]>max then max:=deep[v];
inc(f3[deep[v]]);
dfs(v);
end;
w:=road[w].next;
end;
end;
procedure work(u:longint);
var
v,w,i:longint;
begin
fillchar(f1,sizeof(f1),0);
fillchar(f2,sizeof(f2),0);
fillchar(deep,sizeof(deep),0);
fillchar(flag,sizeof(flag),false);
flag[u]:=true;
w:=list[u];
while w<>0 do
begin
fillchar(f3,sizeof(f3),0);
v:=road[w].toit;
deep[v]:=1;
inc(f3[1]);
max:=1;
dfs(v);
for i:=1 to max do
begin
ans1:=(ans1+f3[i]*f2[i]) mod mo;
ans2:=(ans2+f3[i]*f2[i]) mod mo;
f2[i]:=f2[i]+f1[i]*f3[i];
f1[i]:=f1[i]+f3[i];
end;
w:=road[w].next;
end;
end;
begin
assign(input,'hopetree.in');assign(output,'hopetree.out');
reset(input);rewrite(output);
readln(n);
ans1:=0;
ans2:=233;
for i:=1 to n-1 do
begin
readln(u,v);
add(u,v);
add(v,u);
end;
for i:=1 to n do
work(i);
writeln(ans1+1,' ',ans2+1);
close(input);close(output);
end.