题意:

思路:

 var head,vet,next,len1,len2,x,y,p1,p2,dis,a,b,fan:array[..]of longint;
pre:array[..,..]of longint;
inq:array[..]of boolean;
q:array[..]of longint;
n,m,i,j,ans,tot,source,src,s,t1,t2:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(a,b,c,d:longint);
begin
inc(tot);
next[tot]:=head[a];
vet[tot]:=b;
len1[tot]:=c;
len2[tot]:=d;
head[a]:=tot; inc(tot);
next[tot]:=head[b];
vet[tot]:=a;
len1[tot]:=;
len2[tot]:=-d;
head[b]:=tot;
end; function find(x,y:longint):boolean;
var i:longint;
begin
for i:= to n do
if (x=a[i])and(y=b[i]) then exit(true);
exit(false);
end; function spfa:boolean;
var u,e,v,i,t,w,t1,w1:longint;
begin
for i:= to s do
begin
dis[i]:=maxlongint>>;
inq[i]:=false;
end;
t:=; w:=; t1:=; w1:=; q[]:=source; dis[source]:=; inq[source]:=true;
while t<w do
begin
inc(t); inc(t1);
if t1= then t1:=;
u:=q[t1]; inq[u]:=false;
e:=head[u];
while e<> do
begin
v:=vet[e];
if (len1[e]>)and(dis[u]+len2[e]<dis[v]) then
begin
pre[v,]:=u;
pre[v,]:=e;
dis[v]:=dis[u]+len2[e];
if not inq[v] then
begin
inc(w); inc(w1);
if w1= then w1:=;
q[w1]:=v; inq[v]:=true;
end;
end;
e:=next[e];
end;
end;
if dis[src]=maxlongint>> then exit(false);
exit(true);
end; procedure mcf;
var k,e,t:longint;
begin
k:=src; t:=maxlongint;
while k<>source do
begin
t:=min(t,len1[pre[k,]]);
k:=pre[k,];
end;
k:=src;
while k<>source do
begin
e:=pre[k,];
len1[e]:=len1[e]-t;
len1[fan[e]]:=len1[fan[e]]+t;
ans:=ans+t*len2[e];
k:=pre[k,];
end;
end; begin
assign(input,'guess.in'); reset(input);
assign(output,'guess.out'); rewrite(output);
readln(n);
for i:= to do
if i and = then fan[i]:=i+
else fan[i]:=i-;
for i:= to n do
begin
readln(a[i],b[i]);
inc(x[a[i]]); inc(y[b[i]]);
end;
for i:= to do
if x[i]> then inc(s);
for i:= to do
if y[i]> then inc(s);
source:=s+; src:=s+; s:=s+;
for i:= to do
if x[i]> then
begin
inc(t1); p1[t1]:=i;
add(source,t1,x[i],);
end;
for i:= to do
if y[i]> then
begin
inc(t2); p2[t2]:=i;
add(t1+t2,src,y[i],);
end;
for i:= to t1 do
for j:= to t2 do
if find(p1[i],p2[j]) then add(i,j+t1,,)
else add(i,j+t1,,);
while spfa do mcf;
writeln(ans);
close(input);
close(output);
end.

最新文章

  1. SQL优化技术分析-2:SQL书写的影响
  2. Socket编程——客户端,服务器端的读写操作
  3. Jquery基础之DOM操作
  4. stm32 cortext-M3 类型对齐问题【worldsing笔记】
  5. MYSQL存储过程中的IN、OUT和INOUT
  6. time.h
  7. [Cycle.js] Hyperscript as our alternative to template languages
  8. Codeforce 水题报告
  9. Hadoop2.7.3集群搭建
  10. golang写业务代码,用全局函数还是成员函数
  11. HTML设为首页/加入收藏代码
  12. AES 加密问题
  13. WdatePicker控件Javascript取得当前时间、取得减30分钟时间
  14. treap入门
  15. 【Go命令教程】1. 标准命令详解
  16. angular中的表单数据自定义验证
  17. myeclipse新建jsp文件时弹出默认模板,怎么改成自己修改后的
  18. 2.GlusterFS 安装配置
  19. maven打包遇到的问题
  20. dig指定服务器查询域名解析时间

热门文章

  1. openssh安装、设置指定端口号、免密码登录、变量传递、防暴力破解
  2. spark调试环境搭建
  3. AJPFX分析int 和integer的区别
  4. 让px单位自动转换为rem的方法
  5. RegisterClientScriptBlock和RegisterStartupScript的区别
  6. vb,wps,excel 分裂
  7. MIPS的寄存器、指令和寻址方式的分类
  8. BZOJ4873 LuoguP3749 寿司餐厅
  9. Kafka生产者----向kafka写入数据
  10. [kuangbin带你飞]专题四 最短路练习