比赛 |
20110725 |
评测结果 |
AAAAAAAAAAAAAAAATTTT |
题目名称 |
存在与否 |
最终得分 |
80 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-25 12:46:57 |
显示代码纯文本
program cunzaiyufou;
var
n,i,x,y,c,min,m:longint;
map:array[0..1001,0..1001] of longint;
bz:array[0..1000]of boolean;
dist:array[0..1000]of longint;
procedure sousuo(k,v,father:longint);
var
i:longint;
begin
if k=n+2 then
begin
if dist[0]<min then
min:=dist[0];
exit
end
else
for i:=0 to n do
if (bz[i])and(i<>father)and(map[v,i]>0)and(map[v,i]+dist[v]<min) then
begin
bz[i]:=false;
dist[i]:=dist[v]+map[v,i];
sousuo(k+1,i,v);
bz[i]:=true
end
end;
begin
assign (input,'exists.in');
reset (input);
assign (output,'exists.out');
rewrite (output);
readln (n);
for i:=1 to n-1 do
begin
readln (x,y,c);
map[x,y]:=c;
map[y,x]:=c
end;
readln (m);
for i:=1 to m+1 do
begin
readln (x,y,c);
map[x,y]:=c;
map[y,x]:=c
end;
for i:=0 to n do
bz[i]:=true;
dist[0]:=0;
min:=maxlongint;
sousuo(1,0,0);
writeln (min);
close (input);
close (output)
end.