比赛 |
20120704 |
评测结果 |
AAAAAAAWWWW |
题目名称 |
子集 |
最终得分 |
63 |
用户昵称 |
zhangchi |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2012-07-04 10:33:40 |
显示代码纯文本
type
node=record
v,next:longint;
end;
var
n,m,i,j,tot,t,sum,ans,x,y,long,ran:longint;
v,num:array[1..10000] of longint;
p:array[1..10000] of boolean;
f:array[1..10000] of longint;
a:array[1..2000000] of node;
procedure insert(x,y:longint);
begin
inc(tot);
a[tot].next:=f[x];
f[x]:=tot;
a[tot].v:=y;
end;
procedure sort(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l; j:=r;
m:=v[(l+r) div 2];
repeat
while v[i]>m do inc(i);
while v[j]<m do dec(j);
if i<=j then
begin
t:=v[i]; v[i]:=v[j]; v[j]:=t;
t:=num[i]; num[i]:=num[j]; num[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'subseta.in'); reset(input);
assign(output,'subseta.out'); rewrite(output);
randomize;
readln(n);
for i:=1 to n do
begin
read(v[i]);
num[i]:=i;
end;
readln(m);
for i:=1 to m do
begin
readln(x,y);
insert(x,y);
insert(y,x);
end;
sort(1,n);
ans:=0;
long:=10000000 div n;
for i:=1 to long do
begin
sum:=0;
fillchar(p,sizeof(p),false);
for j:=1 to n do
begin
if p[num[j]]=false then
begin
ran:=random(10000)+1;
if ran<9100 then
begin
sum:=sum+v[j];
p[num[j]]:=true;
t:=f[num[j]];
while t<>0 do
begin
p[a[t].v]:=true;
t:=a[t].next;
end;
end;
end;
end;
if sum>ans then ans:=sum;
end;
writeln(ans);
end.