Stop the Hollyweb! No DRM in HTML5.

[POJ3013]细节spfa

这题……TAT

11402985 HTwood 3013 Accepted 10844K 1032MS Pascal 2009B 2013-03-27 21:21:10
11402592 HTwood 3013 Wrong Answer     Pascal 1995B 2013-03-27 20:32:18
11402558 HTwood 3013 Wrong Answer     Pascal 1998B 2013-03-27 20:28:47
11402487 HTwood 3013 Wrong Answer     Pascal 1998B 2013-03-27 20:20:43
11402470 HTwood 3013 Wrong Answer     Pascal 2000B 2013-03-27 20:18:05
11402420 HTwood 3013 Wrong Answer     Pascal 1968B 2013-03-27 20:12:43
11402417 HTwood 3013 Wrong Answer     Pascal 1994B 2013-03-27 20:12:06
11402408 HTwood 3013 Wrong Answer     Pascal 2851B 2013-03-27 20:10:27
11402396 HTwood 3013 Wrong Answer     Pascal 2853B 2013-03-27 20:08:00
11402302 HTwood 3013 Wrong Answer     Pascal 2729B 2013-03-27 19:55:34
11402243 HTwood 3013 Wrong Answer     Pascal 2729B 2013-03-27 19:47:10
11402229 HTwood 3013 Wrong Answer     Pascal 2710B 2013-03-27 19:45:26
11402220 HTwood 3013 Wrong Answer     Pascal 2712B 2013-03-27 19:43:43
11402204 HTwood 3013 Wrong Answer     Pascal 2718B 2013-03-27 19:41:33
11402186 HTwood 3013 Wrong Answer     Pascal 2731B 2013-03-27 19:39:06
11402172 HTwood 3013 Runtime Error     Pascal 2724B 2013-03-27 19:35:52
11402170 HTwood 3013 Runtime Error     Pascal 2724B 2013-03-27 19:35:27
11402137 HTwood 3013 Wrong Answer     Pascal 2644B 2013-03-27 19:29:52

 

1、用int64存储信息
2、似乎edge要开200000
3、n=0或1时输出0
4、确认你的spfa没写错,访问下一个节点前先对当前节点置v[x]=true(环!),最后置为false
5、最后检验时要记得从i=2时开始检验
6、inf要是1<<61左右,太大会爆,太小不行
7、双向边,重边
program p3013;

Type
 rec=record
   e,w,next:int64;
 end;

Var
 a:array[0..200002] of rec;
 b,g,q,dt:array[0..200002] of int64;
 v:array[0..200002] of boolean;
 n,m,t,top,ans,st,ed,ww:int64;
 i:longint;
 ok:boolean;

Procedure fopen;
  begin
  assign(input,'p3013.in');
  assign(output,'p3013.out');
  reset(input);
  rewrite(output);
end;

Procedure fclose;
  begin
  close(input);
  close(output);
end;

Procedure Add(ss,ee,ww:longint);
  begin
  inc(top);
  with a[top] do
    begin
    next:=b[ss];
    e:=ee;
    w:=ww;
  end;
  b[ss]:=top;
end;

Procedure spfa;
var
 close,open,o,x:int64;
 y:rec;
 i:longint;
  begin
  fillchar(v,sizeof(v),false);
  fillchar(q,sizeof(q),0);
  for i:=1 to 200000 do dt[i]:=1 shl 61;
  dt[1]:=0;
  v[1]:=true;
  close:=0;open:=1;
  q[1]:=1;
  while close<>open do
    begin
    close:=close mod n+1;
    x:=q[close];v[x]:=true;
    //v[x]:=false;
    o:=b[x];
    while o<>0 do
      begin
      y:=a[o];
      o:=y.next;
      with y do
        begin
        if dt[e]>dt[x]+w then
          begin
          dt[e]:=dt[x]+w;
        if not v[e] then
          begin
          open:=open mod n+1;
          q[open]:=e;
          v[e]:=true;
        end;
        end;
      end;
    end;
    //writeln('x=',x);
    v[x]:=false;
  end;
end;
  

  begin

  readln(t);

  while t>0 do
    begin
    top:=0;
    dec(t);
    readln(n,m);
    fillchar(a,sizeof(a),0);
    fillchar(b,sizeof(b),0);
    for i:=1 to n do
      read(g[i]);
    for i:=1 to m do
      begin
      read(st,ed,ww);
      //if st=ed then continue;
      Add(st,ed,ww);
      Add(ed,st,ww);
    end;
    if (n<2) then writeln(0) else begin
    //prepare;
      spfa;
      ans:=0;
      ok:=true;
      for i:=2 to n do if  dt[i]<1 shl 61 then ans:=ans+dt[i]*g[i] else begin ok:=false; writeln('No Answer');break;end;
      if ok then writeln(ans); end;
      
   
  end;

end.

 

posted on 2013-03-27 21:34  灰天飞雁  阅读(291)  评论(0编辑  收藏  举报

填写您的邮件地址,订阅我们的精彩内容:  点击这里给我发消息

添加到收藏夹