铲雪车问题

2025-03-17 12:52:31
推荐回答(4个)
回答1:

  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;

  procedure initfile;
  begin
  assign(input,'one.in');
  reset(input);
  assign(output,'one.out');
  rewrite(output);
  end;

  procedure 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.

回答2:

TZ我看出你来了

回答3:

、、、 吴老师叫做你就上网问、、、

回答4:

你自己慢慢作磨吧!