比赛 20120704 评测结果 AAAAAAAWTTT
题目名称 子集 最终得分 63
用户昵称 IMSL77 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 11:59:41
显示代码纯文本
program main;
type
  integer=longint;
const
  maxn=10010;
  maxm=100010;
var
  n,m:integer;
  w:array[1..maxn] of integer;
  ver:array[1..maxn] of integer;
  en,next,tick:array[1..maxm] of integer;
  f1:array[1..maxn] of boolean;
  f2:array[1..maxm] of boolean;
  ans,sum:integer;

  procedure Fopen;
  begin
    assign(input,'subseta.in');
    reset(input);
    assign(output,'subseta.out');
    rewrite(output);
  end;

  procedure Fclose;
  begin
    close(input);
    close(output);
  end;

  procedure Init;
  var
    i:integer;
    u,v,tot:integer;
  begin
    readln(n);
    sum:=0;
    for i:=1 to n do
    begin
      read(w[i]);
      inc(sum,w[i]);
    end;
    read(m);
    fillchar(ver,sizeof(ver),0);
    fillchar(next,sizeof(next),0);
    tot:=0;
    for i:=1 to m do
    begin
      read(u,v);
      inc(tot);
      en[tot]:=v; next[tot]:=ver[u]; ver[u]:=tot;
      tick[tot]:=i;
      inc(tot);
      en[tot]:=u; next[tot]:=ver[v]; ver[v]:=tot;
      tick[tot]:=i;
    end;
  end;

  function Cheat:integer;
  var
    i,p,q,k,res:integer;
    flag:boolean;
  begin
    fillchar(f1,sizeof(f1),false);
    fillchar(f2,sizeof(f2),true);
    p:=0;  res:=0;
    while p<m do
    begin
      q:=random(n-1)+1;
      while f1[q] do q:=random(n-1)+1;
      f1[q]:=true;
      k:=ver[q];
      flag:=false;
      while k>0 do
      begin
        if f2[tick[k]] then
        begin
          f2[tick[k]]:=false;
          flag:=true;
          inc(p);
        end;
        k:=next[k];
      end;
      if flag then res:=res+w[q];
    end;
    exit(res);
  end;
  function min(a,b:integer):integer;
  begin
    if a<b then exit(a) else exit(b);
  end;

  procedure Solve;
  var
    i:integer;
  begin
    ans:=maxlongint;
    for i:=1 to 1000 do ans:=min(ans,Cheat);
    writeln(sum-ans);
  end;

begin
  Fopen;
  Init;
  Solve;
  Fclose;
end.