铲雪车问题
发布网友
发布时间:2022-04-20 21:27
我来回答
共4个回答
热心网友
时间:2023-08-30 02:21
program one;
const maxn = 100000;
maxv = (maxn-1)*2;
type vtype=record
b,c,p:longint;
end;
var n,s,i,a,b,c,total:longint;
v:array[1..maxv] of vtype;
lista:array[1..maxn] of longint;
p:array[1..maxn] of boolean;
procere initfile;
begin
assign(input,'one.in');
reset(input);
assign(output,'one.out');
rewrite(output);
end;
procere closefile;
begin
close(input);
close(output);
end;
function search(x : longint) : longint;
var d, max : longint;
y : longint;
begin
p[x]:=true;
y:=lista[x];
max:=0;
while y<>0 do
begin
if not(p[v[y].b]) then
d:=v[y].c+search(v[y].b)
else
d:=0;
if d>max then max:=d;
y:=v[y].p;
end;
search:=max;
end;
begin
initfile;
readln(n,s);
total := 0;
for i:=1 to n do lista[i]:=0;
for i:=1 to n-1 do
begin
readln(a,b,c);
total:=total+c;
v[i*2-1].b:=b;
v[i*2-1].c:=c;
v[i*2-1].p:=lista[a];
lista[a]:=i*2-1;
v[i*2].b:=a;
v[i*2].c:=c;
v[i*2].p:=lista[b];
lista[b]:=i*2;
end;
for i:=1 to n do p[i]:=false;
total:=total*2-search(s);
writeln(total);
closefile;
end.
热心网友
时间:2023-08-30 02:22
TZ我看出你来了
热心网友
时间:2023-08-30 02:22
、、、 吴老师叫做你就上网问、、、
热心网友
时间:2023-08-30 02:23
你自己慢慢作磨吧!