zoukankan      html  css  js  c++  java
  • [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.
    
  • 相关阅读:
    BZOJ1999或洛谷1099&BZOJ2282或洛谷2491 树网的核&[SDOI2011]消防
    BZOJ1912或洛谷3629 [APIO2010]巡逻
    CH6202 黑暗城堡
    POJ2728 Desert King
    JoyOI1391 走廊泼水节
    洛谷1073 最优贸易
    POJ3662或洛谷1948 Telephone Lines
    BZOJ1106 [POI2007]立方体大作战tet
    ubuntu 16.04 安装genymotion
    ubuntu下搭建android开发环境核心篇安装AndroidStudio、sdk、jdk
  • 原文地址:https://www.cnblogs.com/htfy/p/2985429.html
Copyright © 2011-2022 走看看