比赛 2008haoi模拟训练2 评测结果 TTTTT
题目名称 公路建设 最终得分 0
用户昵称 cuixiaofei 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-04-23 11:18:03
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_04_23;
program road;
  const
    city                        =550;
  type
    sss                         =record
                     x,y,ym     :longint;
                     s          :real;
                                end;
    mmm                         =record
                     sz        :real;
                     zz        :longint;
                                end;
  var
    n,m,ge,q,shuz               :longint;
    he                          :real;
    ji                          :array[1..city,1..city] of mmm;
    a                           :array[1..city*4] of sss;
    shu,pc                      :array[1..city] of longint;
    f1,f2                       :text;
  procedure quhuan(k:longint);
    var
      i,st,ed,panduan           :longint;
      max                       :real;
      sou                       :array[1..city,1..2] of longint;
      pcc                       :array[1..city] of longint;
    function panpan(zhao,bi:longint):longint;
      var
        i                       :longint;
      begin
        panpan:=0;
        while sou[zhao,2]<>0 do
          begin
            zhao:=sou[zhao,2];
            if sou[zhao,1]=bi then
              begin
                 panpan:=1;
                 exit;
              end;
          end;
      end;
  begin
    fillchar(pcc,sizeof(pcc),0);
    sou[1,1]:=a[k].x;
    sou[1,2]:=0;
    pcc[sou[1,1]]:=1;
    st:=0;
    ed:=1;
    panduan:=0;
    while (st<=ed) and (panduan=0) do
      begin
        inc(st);
        for i:=1 to n do
          begin
          if (ji[sou[st,1],i].sz>0) and (pcc[i]=0) then
            begin
              inc(ed);
              sou[ed,1]:=i;
              sou[ed,2]:=st;
              pcc[i]:=1;
            end
          else if (ji[sou[st,1],i].sz>0) and (pcc[i]=1) and (panpan(st,i)=0) then
            begin
              panduan:=1;
              inc(ed);
              sou[ed,1]:=i;
              sou[ed,2]:=st;
            end;
          if panduan=1 then
            break;
          end
      end;
    max:=0;
    if ji[sou[ed,1],sou[1,1]].sz>max then
      begin
        max:=ji[sou[ed,1],sou[1,1]].sz;
        panduan:=ji[sou[ed,1],sou[1,1]].zz;
      end;
    while sou[ed,2]<>0 do
      begin
        if ji[sou[ed,1],sou[sou[ed,2],1]].sz>max then
          begin
            max:=ji[sou[ed,1],sou[sou[ed,2],1]].sz;
            panduan:=ji[sou[ed,1],sou[sou[ed,2],1]].zz;
          end;
        ed:=sou[ed,2];
      end;
    ji[a[panduan].x,a[panduan].y].sz:=0;
    ji[a[panduan].y,a[panduan].x].sz:=0;
    ji[a[panduan].x,a[panduan].y].zz:=0;
    ji[a[panduan].y,a[panduan].x].zz:=0;
    a[panduan].ym:=0;
    he:=he-max;
  end;
  procedure jinru(k:longint);
  begin
    if (pc[a[k].x]=0) and (pc[a[k].y]=0) then
      begin
        writeln(f2,0);
        a[k].ym:=1;
        he:=he+a[k].s;
        ji[a[k].x,a[k].y].sz:=a[k].s;
        ji[a[k].y,a[k].x].sz:=a[k].s;
        ji[a[k].x,a[k].y].zz:=k;
        ji[a[k].x,a[k].y].zz:=k;
        inc(ge,2);
        inc(pc[a[k].x]);
        inc(pc[a[k].y]);
        exit;
      end
    else if  (pc[a[k].x]>0) and (pc[a[k].y]>0) then
      begin
        he:=he+a[k].s;
        a[k].ym:=1;
        if ji[a[k].x,a[k].y].sz>0 then
          begin
            if ji[a[k].x,a[k].y].sz<a[k].s then
              begin
                he:=he-a[k].s;
                a[k].ym:=0;
              end
            else
              begin
                he:=he-ji[a[k].x,a[k].y].sz;
                a[ji[a[k].x,a[k].y].zz].ym:=0;
                ji[a[k].x,a[k].y].sz:=a[k].s;
                ji[a[k].y,a[k].x].sz:=a[k].s;
                ji[a[k].x,a[k].y].zz:=k;
                ji[a[k].y,a[k].x].zz:=k;
              end;
          end
        else
          begin
            ji[a[k].x,a[k].y].sz:=a[k].s;
            ji[a[k].y,a[k].x].sz:=a[k].s;
            ji[a[k].x,a[k].y].zz:=k;
            ji[a[k].y,a[k].x].zz:=k;
            quhuan(k);
          end;
        if ge=n then
          writeln(f2,he/2:0:1)
      end
    else
      begin
        inc(pc[a[k].x]);
        inc(pc[a[k].y]);
        ji[a[k].x,a[k].y].sz:=a[k].s;
        ji[a[k].y,a[k].x].sz:=a[k].s;
        ji[a[k].x,a[k].y].zz:=k;
        ji[a[k].y,a[k].x].zz:=k;
        a[k].ym:=1;
        he:=he+a[k].s;
        inc(ge);
        if ge=n then
          writeln(f2,he/2:0:1);
      end;
  end;

  procedure init;
    var
      i,a1,a2,a3                :longint;
  begin
    fillchar(a,sizeof(a),0);
    fillchar(ji,sizeof(ji),0);
    assign(f1,'road.in');
    reset(f1);
    assign(f2,'road.out');
    rewrite(f2);
    ge:=0;
    he:=0;
    readln(f1,n,m);
    for i:=1 to m do
      begin
        readln(f1,a[i].x,a[i].y,a[i].s);
        q:=i;
        jinru(i);
      end;
    close(f2);
    close(f1);
  end;
  begin
    init;
  end.