Asteroids_poj3041_最大匹配

题目

vijos 1204 CoVH之柯南开锁

见http://blog.csdn.net/a_loud_name/article/details/51737072


代码

type
  arr=record
    x,y,w:longint;
    next:longint;
end;

var
  a:array[1..10000] of arr;
  v:array[1..30000] of boolean;
  st,ls:array[1..30000] of longint;
  i,j:longint;
  n,m,nm:longint;
  k:char;

function find(r:longint):boolean;
var
  i,j,k:longint;
begin
  find:=true;
  i:=ls[r];
  while i<>0 do
    begin
      with a[i] do
        if not v[y]
          then
            begin
              k:=st[y]; st[y]:=r; v[y]:=true;
              if (k=0) or find(k) then exit;
              st[y]:=k;
            end;
      i:=a[i].next;
    end;
  find:=false;
end;

procedure main;
var
  i,j,k:longint;
  z:boolean;
begin
  for i:=1 to n do
    begin
      fillchar(v,sizeof(v),0);
      z:=find(i);  
    end;
end;

begin
  readln(n,m);
  nm:=0;
  for i:=1 to m do
    begin
      nm:=nm+1;
      with a[nm] do
            begin
              readln(x,y);
              y:=y+n;
              next:=ls[x];
              ls[x]:=nm;
            end;
    end;
  main;
  j:=0;
  for i:=n to n+m do
    if st[i]<>0 then j:=j+1;
  write(j);
end.


posted @ 2016-06-23 16:25  一个响亮的蒟蒻  阅读(104)  评论(0编辑  收藏  举报