题目的意思是要选一些数,但是这些数如果满足两个条件的话就不能一起被选。

type
arr=record
toward,next,cap:longint;
end; const
maxn=;
maxm=;
var
gap,first,cur,d,num1,num2:array[..maxn]of longint;
edge:array[..maxm]of arr;
tot,s,t,n,esum,sum:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(j,k,l:longint);
begin
//writeln(j,' ',k,' ',l);
inc(esum);
edge[esum].toward:=k;
edge[esum].next:=first[j];
first[j]:=esum;
edge[esum].cap:=l;
end; procedure addedge(j,k,l:longint);
begin
add(j,k,l);
add(k,j,);
end; function sap(x,flow:longint):longint;
var
i,too,more,now:longint;
begin
if x=t then exit(flow);
now:=;
i:=cur[x];
while i>= do begin
too:=edge[i].toward;
if (d[x]=d[too]+) and (edge[i].cap>) then begin
more:=sap(too,min(edge[i].cap,flow-now));
dec(edge[i].cap,more);
inc(edge[i xor ].cap,more);
inc(now,more);
cur[x]:=i;
if flow=now then exit(flow);
end;
i:=edge[i].next;
end;
dec(gap[d[x]]);
if gap[d[x]]= then d[s]:=tot;
inc(d[x]);
inc(gap[d[x]]);
cur[x]:=first[x];
exit(now);
end; function maxflow:longint;
var
i,ans:longint;
begin
fillchar(d,sizeof(d),);
fillchar(gap,sizeof(gap),);
gap[]:=tot;
for i:= to tot do cur[i]:=first[i];
ans:=;
while d[s]<tot do
inc(ans,sap(s,maxlongint));
exit(ans);
end; function gcd(x,y:longint):boolean;
begin
if y= then exit(x=);
exit(gcd(y,x mod y));
end; procedure into;
var
i,j,tot1,tot2,k:longint;
begin
readln(n);
esum:=-;
fillchar(first,sizeof(first),);
tot1:=;
tot2:=;
for i:= to n do begin
read(j);
if j and = then begin
inc(tot1);
num1[tot1]:=j;
end
else begin
inc(tot2);
num2[tot2]:=j;
end;
inc(sum,j);
end;
for i:= to tot1 do
for j:= to tot2 do
if gcd(num1[i],num2[j]) then begin
k:=sqr(num1[i])+sqr(num2[j]);
if sqr(trunc(sqrt(k)))=k then addedge(i,j+tot1,maxlongint);
end;
// writeln;
tot:=tot1+tot2+;
s:=tot-;
t:=tot;
for i:= to tot1 do addedge(s,i,num1[i]);
for i:= to tot2 do addedge(i+tot1,t,num2[i]);
{ for i:=1 to tot1 do writeln(i,' ',num1[i]);
for i:=1 to tot2 do writeln(i,' ',num2[i]); }
end; begin
into;
writeln(sum-maxflow);
readln;
readln;
end.
04-29 04:59