比赛 2008haoi模拟训练2 评测结果 EETTT
题目名称 公路建设 最终得分 0
用户昵称 francis 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-04-23 11:47:05
显示代码纯文本
program road;
type
node=record
   p1:longint;
   p2:longint;
   w:longint;
end;
const
max1=2000;
var
a:array[1..max1,1..max1]of longint;
p:array[1..max1]of longint;
b:array[1..max1] of node;
d:array[1..max1]of longint;
hh,fa,z,v,x1,x2,ww,h,point,min,x,y,num,i,j,n,m:longint;
bo:boolean;
f1,f2:text;

procedure init;
begin
assign(f1,'road.in');
assign(f2,'road.out');
reset(f1);
rewrite(f2);
read(f1,n,m);
for i:=1 to m do
read(f1,b[i].p1,b[i].p2,b[i].w);
for i:=1 to n do
p[i]:=0;
min:=0;
z:=1;
end;

procedure so(point,fa:longint);
var
q:longint;
begin
if point=y then begin hh:=h; bo:=true;  end;
if bo=true then exit;
for q:=1 to n do
begin
if (a[point,q]>0)and(q<>fa) then begin inc(h); d[h]:=q; so(q,point); dec(h); end;
end;
end;

begin
init;
for i:=1 to  m  do
begin
if (p[b[i].p1]=0)and(p[b[i].p2]=0)and(z=i) then begin  inc(num);   inc(z);
   p[b[i].p1]:=num; p[b[i].p2]:=num;  a[b[i].p1,b[i].p2]:=b[i].w;
   a[b[i].p2,b[i].p1]:=b[i].w;    min:=min+b[i].w;
   bo:=false;v:=p[1];
   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
   end;

if (p[b[i].p1]>0)and(p[b[i].p2]=0)and(z=i) then begin inc(z);
   p[b[i].p2]:=p[b[i].p1];  a[b[i].p1,b[i].p2]:=b[i].w;
   a[b[i].p2,b[i].p1]:=b[i].w;    min:=min+b[i].w;
   bo:=false;v:=p[1];
   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
   end;

if (p[b[i].p1]=0)and(p[b[i].p2]>0)and(z=i) then begin inc(z);
   p[b[i].p1]:=p[b[i].p2];  a[b[i].p1,b[i].p2]:=b[i].w;
    a[b[i].p2,b[i].p1]:=b[i].w;    min:=min+b[i].w;
    bo:=false;v:=p[1];
   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
    end;

if (p[b[i].p1]>0)and(p[b[i].p2]<>p[b[i].p1])and(z=i) then begin inc(z);
   x:=p[b[i].p2];
   for j:=1 to n do
   if p[j] =x then  p[j]:=p[b[i].p1];
   a[b[i].p1,b[i].p2]:=b[i].w;  a[b[i].p2,b[i].p1]:=b[i].w;
   bo:=false;v:=p[1];
   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
   end;

if (p[b[i].p1]>0)and(p[b[i].p2]=p[b[i].p1])and(z=i) then  begin

  if (a[b[i].p1,b[i].p2]>0)and(z=i) then begin
   inc(z);
   if b[i].w<a[b[i].p1,b[i].p2] then begin
   min:= min-a[b[i].p1,b[i].p2]+b[i].w;
   a[b[i].p1,b[i].p2]:=b[i].w;
   end;
   bo:=false;v:=p[1];
   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
   end;

  if (a[b[i].p1,b[i].p2]=0)and(z=i) then begin
  inc(z);
  bo:=false;  y:=b[i].p2;  d[1]:=b[i].p1; ww:=0; h:=1; d[h]:=b[i].p1;
   so(b[i].p1,50000);
  inc(hh); d[hh]:=y;
  for j:=1 to (hh-1) do
    begin if ww<a[d[j],d[j+1]] then begin ww:=a[d[j],d[j+1]];
                            x1:=d[j]; x2:=d[j+1];
    end;  end;
  if ww>b[i].w  then
  begin
  a[x1,x2]:=0; a[x2,x1]:=0;
   a[b[i].p1,b[i].p2]:=b[i].w;
   a[b[i].p1,b[i].p1]:=b[i].w;
   min:=min-ww+b[i].w;
  end;
  bo:=false;v:=p[1];

   if v<>0 then begin
   for j:=2 to n do
   if p[j]<>v then bo:=true;
   end;
   if (bo=false)and(v<>0) then  writeln(f2,(min/2):0:1) else writeln(f2,0);
  end;
 end;
end;
close(f1);
close(f2);
end.