比赛 |
20100419 |
评测结果 |
WWWTT |
题目名称 |
烟花的寿命 |
最终得分 |
0 |
用户昵称 |
ybh |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-04-19 11:30:12 |
显示代码纯文本
program firework;
var
cost:array[0..1000,0..1000] of integer;
q,fa,dist,fa2,path:array[0..1000] of integer;
bb:array[0..1000] of boolean;
b:array[0..1000,0..1000] of boolean;
tt,n,k,i,j,s,max,maxs,maxi,max2,max2s,max2i,p,tot,r1,r2,t,h:integer;
begin
assign(input,'firework.in');
reset(input);
assign(output,'firework.out');
rewrite(output);
readln(tt);
for k:=1 to tt do
begin
readln(n);
fillchar(cost,sizeof(cost),0);
fillchar(fa2,sizeof(fa2),0);
for i:=1 to n-1 do
begin
readln(r1,r2);
cost[r1,r2]:=-1;
cost[r2,r1]:=-1;
end;
max2:=0;
for s:=1 to n do
begin
fillchar(bb,sizeof(bb),false);
fillchar(dist,sizeof(dist),0);
fillchar(q,sizeof(q),0);
fillchar(fa,sizeof(fa),0);
fillchar(b,sizeof(b),false);
h:=0;
t:=1;
q[t]:=s;
bb[s]:=true;
b[s,s]:=true;
while h<>t do
begin
h:=(h mod n)+1;
for i:=1 to n do
begin
if (cost[q[h],i]<0) and (dist[q[h]]+cost[q[h],i]<dist[i]) and (b[q[h],i]=false) then
begin
dist[i]:=dist[q[h]]+cost[q[h],i];
fa[i]:=q[h];
b[i]:=b[q[h]];
b[i,i]:=true;
if bb[i]=false then
begin
t:=(t mod n)+1;
q[h]:=i;
bb[i]:=true
end
end
end;
bb[q[h]]:=false;
end;
max:=0;
for i:=1 to n do
if dist[i]<max then
begin
max:=dist[i];
maxs:=s;
maxi:=i;
end;
if max<max2 then
begin
max2:=max;
max2s:=maxs;
max2i:=maxi;
fa2:=fa
end
end;
writeln(-max2);
p:=max2i;
tot:=0;
repeat
tot:=tot+1;
path[tot]:=p;
p:=fa2[p];
until p=max2s;
writeln(max2s);
for i:=tot downto 1 do
writeln(path[i]);
end;
close(input);
close(output)
end.