比赛 20120704 评测结果 WWWWWWAWWWW
题目名称 子集 最终得分 9
用户昵称 fuhao 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 11:58:02
显示代码纯文本
const maxn=10001;
var
 n,i,m,s,t,min,ans,p,max,tot,x,y:longint; found:boolean;
 v:array[0..maxn] of longint;
 a,h,hnum,c,next,against,link:array[0..maxn*10] of longint;
 procedure sap(k:longint);
 var i,hmin,temp:longint;
 begin
  if k=t then
   begin
    found:=true;
    ans:=ans+max;
    exit;
   end;
  i:=a[k]; hmin:=t-1; temp:=max;
  while i<>0 do
   begin
    if c[i]>0 then
    begin
    if h[link[i]]+1=h[k] then
     begin
      if c[i]<max then max:=c[i];
      sap(link[i]);
      max:=temp;
      if h[0]>=t then exit;
      if found then break;
     end;
    if h[link[i]]<hmin then hmin:=h[link[i]];
    end;
    i:=next[i];
   end;
  if found then
   begin
    dec(c[i],max);
    inc(c[against[i]],max);
   end else
   begin
    dec(hnum[h[k]]);
    if hnum[h[k]]=0 then h[0]:=2*n+1;
    h[k]:=hmin+1;
    inc(hnum[h[k]]);
   end;
 end;
 procedure insert(x,y,z:longint);
 begin
  inc(tot); next[tot]:=a[x]; a[x]:=tot;
  link[tot]:=y; c[tot]:=z; against[tot]:=tot+1;
  inc(tot); next[tot]:=a[y]; a[y]:=tot;
  link[tot]:=x; against[tot]:=tot-1;
 end;
begin
 assign(input,'subseta.in'); reset(input);
 assign(output,'subseta.out'); rewrite(output);
 readln(n);
 for i:=1 to n do read(v[i]);
 read(m);
 for i:=1 to m do
  begin
   read(x,y);
   insert(x,y+n,v[y]);
   insert(y,x+n,v[x]);
  end;
 s:=0; t:=2*n+1;
 for i:=1 to n do insert(0,i,maxlongint);
 for i:=n+1 to 2*n do insert(i,t,v[i-n]);
 hnum[0]:=t+1;
 while h[0]<t do
  begin
   found:=false;
   max:=maxlongint div 2;
   sap(s);
  end;
 p:=0;
 for i:=1 to n do p:=p+v[i];
 writeln(p-ans);
 close(input); close(output);
end.