比赛 |
20120705 |
评测结果 |
AAAAAATAAA |
题目名称 |
塔防游戏 |
最终得分 |
90 |
用户昵称 |
czp |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-05 11:45:46 |
显示代码纯文本
var
pa,c,lt:array[0..1000,0..1000] of longint;
l,d:array[0..1000] of longint;
vh,h:array[0..1000] of longint;
o:array[0..1000] of boolean;
i,j,m,n,s,t,xx,yy,zz,k,flow,mf,kk:longint;
oo:boolean;
procedure dfs(i:longint);
var mh,tp,j:longint;
begin
tp:=mf;mh:=n-1;
if i=t then begin inc(flow,mf);oo:=true;exit;end;
for j:=1 to n do
if c[i,j]>0 then
begin
if h[i]=h[j]+1 then
begin
if mf>c[i,j] then mf:=c[i,j];
dfs(j);
if h[s]>=n then exit;
if oo then break;
mf:=tp;
end;
if h[j]<mh then mh:=h[j];
end;
if not oo then
begin
dec(vh[h[i]]);
if vh[h[i]]=0 then h[s]:=n;
h[i]:=mh+1;
inc(vh[h[i]]);
end else begin
inc(c[j,i]);
dec(c[i,j]);end;
end;
begin
assign(input,'defence.in');reset(input);
assign(output,'defence.out');rewrite(output);
readln(n,m,s,t);
fillchar(pa,sizeof(pa),$7f div 3);
for i:=1 to m do
begin
readln(xx,yy,zz);
pa[xx,yy]:=zz;
pa[yy,xx]:=zz;
end;
fillchar(d,sizeof(d),$7f div 3);
d[s]:=0;
for i:=1 to n do
begin
k:=0;
for j:=1 to n do if not o[j] then
if d[j]<d[k] then k:=j;
o[k]:=true;
if k=0 then break;
l[0]:=0;
for j:=1 to n do
if not o[j] then
if d[k]+pa[k,j]<=d[j] then
begin
if d[k]+pa[k,j]<d[j] then
begin
for kk:=1 to lt[j,0] do c[lt[j,kk],j]:=0;
lt[j,0]:=0;
inc(l[0]);
l[l[0]]:=j;
end;
if d[k]+pa[k,j]=d[j] then
begin
inc(l[0]);
l[l[0]]:=j;
end;
d[j]:=d[k]+pa[k,j];
end;
for j:=1 to l[0] do
begin
c[k,l[j]]:=1;
inc(lt[l[j],0]);
lt[l[j],lt[l[j],0]]:=k;
end;
end;
fillchar(o,sizeof(o),0);
flow:=0;vh[0]:=n;
while h[s]<n do
begin
oo:=false;
mf:=maxlongint;
dfs(s);
end;
writeln(flow);
close(input);close(output);
end.