比赛 |
20110723 |
评测结果 |
EEEEEE |
题目名称 |
圣诞节 |
最终得分 |
0 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-23 12:33:17 |
显示代码纯文本
const
oo=maxlongint div 2;
var
n,ans,j,i,nn:longint;
h,age,q,d,last:array[0..1000000]of longint;
w,c:array[0..2002,0..2002]of longint;
v:array[0..100000]of boolean;
function spfa:boolean;
var
h,x,i,t:longint;
begin
h:=1;
t:=1;
q[1]:=0;
for i:=0 to n do
begin
v[i]:=false;
d[i]:=oo;
last[i]:=-1;
end;
d[0]:=0;
v[0]:=true;
repeat
x:=q[h];
for i:=0 to n do
if (c[x,i]>0)and(d[x]+w[x,i]<d[i]) then
begin
d[i]:=d[x]+w[x,i];
last[i]:=x;
if not v[i] then
begin
v[i]:=true;
inc(t);
q[t]:=i;
end;
end;
v[x]:=false;
inc(h);
until h>t;
if d[n]=oo then exit(false);
exit(true);
end;
procedure change;
var
i:longint;
begin
i:=n;
while last[i]<>-1 do
begin
dec(c[last[i],i]);
inc(c[i,last[i]]);
i:=last[i];
end;
end;
begin
assign(input,'christmas.in'); reset(input);
assign(output,'christmas.out'); rewrite(output);
readln(n);
for i:=1 to n+n do
begin
readln(h[i],age[i]);
end;
for i:=1 to n do
for j:=n+1 to n+n do
begin
c[i,j]:=1;
w[i,j]:=sqr(h[i]-h[j])+sqr(age[i]-age[j]);
w[j,i]:=-w[j,i];
end;
for i:=1 to n do
c[0,i]:=1;
for i:=n+1 to n+n do
c[i,n+n+1]:=1;
nn:=n;
n:=n+n+1;
while spfa do change;
ans:=-oo;
for i:=1 to nn do
for j:=nn+1 to nn+nn do
if (c[i,j]=0)and(w[i,j]>ans) then ans:=w[i,j];
writeln(ans);
close(input);
close(output);
end.