Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁有大数据啊!我用数组模拟邻接表+spfa,结果RE,好悲剧啊!! program asdf; var ans:int64; q:array[0..100000] of longint; head,tail,k,p,i,n,m,x:longint; f:array[0..50000] of boolean; w,t,dist:array[0..50000] of longint; nu,d:array[0..50000,0..200] of longint; procedure init; var a,b,c,i:longint; begin fillchar(w,sizeof(w),0); readln(n,m); for i:=1 to n do read(w[i]); readln; fillchar(t,sizeof(t),0); fillchar(nu,sizeof(nu),0); fillchar(d,sizeof(d),0); for i:=1 to m do begin readln(a,b,c); inc(t[a]); inc(t[b]); nu[a,t[a]]:=b; d[a,t[a]]:=c; nu[b,t[b]]:=a; d[b,t[b]]:=c; end; end; begin readln(k); for p:=1 to k do begin init; fillchar(f,sizeof(f),0); fillchar(q,sizeof(q),0); head:=0; tail:=1; q[1]:=1; f[1]:=true; fillchar(dist,sizeof(dist),127); dist[1]:=0; while head<>tail do begin head:=(head+1) mod 100000; x:=q[head]; f[x]:=false; for i:=1 to t[x] do if dist[nu[x,i]]>dist[x]+d[x,i] then begin dist[nu[x,i]]:=dist[x]+d[x,i]; if not f[nu[x,i]] then begin tail:=(tail+1) mod 100000; q[tail]:=nu[x,i]; f[nu[x,i]]:=true; end; end; end; ans:=0; for i:=1 to n do if dist[i]>2147000000 then begin writeln('No Answer'); close(input); close(output); halt; end else ans:=ans+dist[i]*w[i]; writeln(ans); end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator