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 |
dijstra16毫秒!program ss; type thing=record p,l,x:longint; end; var a:array[1..100] of thing; dist:array[1..100] of longint; hash:array[1..100] of boolean; map:array[1..100,1..100] of longint; can:array[1..100] of boolean; i,j,k,m,n,s,t,x,y,z,min,ans,l:longint; begin readln(m,n); for i:=1 to n do for j:=1 to n do map[i,j]:=1000000000; for i:=1 to n do begin readln(a[i].p,a[i].l,a[i].x); for j:=1 to a[i].x do begin readln(y,z); map[i,y]:=z; end; end; if a[1].x=0 then begin writeln(a[1].p); halt; end; ans:=1000000000; for i:=1 to n do begin if not ((a[1].l>=a[i].l-m) and (a[1].l<=a[i].l)) then continue; s:=0; fillchar(can,sizeof(can),false); fillchar(hash,sizeof(hash),false); for j:=1 to n do if (a[j].l>=a[i].l-m) and (a[j].l<=a[i].l) then begin inc(s); can[j]:=true; end; hash[1]:=true; for j:=1 to n do if can[j] then dist[j]:=map[1,j]; for l:=1 to s-1 do begin min:=1000000000; for j:=1 to n do if can[j] and (not hash[j]) and (dist[j]<min) then begin min:=dist[j]; k:=j; end; hash[k]:=true; for j:=1 to n do if can[j] and (not hash[j]) and (dist[j]>dist[k]+map[k,j]) then dist[j]:=dist[k]+map[k,j]; end; for j:=1 to n do if can[j] and (ans>dist[j]+a[j].p) then ans:=dist[j]+a[j].p; end; if a[1].p>ans then writeln(ans) else writeln(a[1].p); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator