ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1109. Conference

Could anyone help me?
Posted by SunCat 27 Feb 2003 17:52
program Ural_1109;
type  tnode=^node;
      node=record
            y:integer;
            next:tnode;
           end;
const maxn=1000;
var g:array[1..maxn] of tnode;
    cover:array[1..maxn] of boolean;
    link:array[1..maxn] of integer;
    n,m:integer;
    can:boolean;

procedure init;
var i,t,a,b:integer;
    p:tnode;
begin
  fillchar(g,sizeof(g),0);
  fillchar(cover,sizeof(cover),0);
  fillchar(link,sizeof(link),0);
  readln(m,n,t);
  for i:=1 to t do
   begin
     readln(a,b);
     new(p);
     p^.y:=b;p^.next:=nil;
     if g[a]<>nil then
       begin
         p^.next:=g[a];
         g[a]:=p;
       end
     else
       g[a]:=p;
   end;
end;

procedure find(i:integer);
var j,q,k:integer;
    p:tnode;
begin
   if cover[i] then exit;
   cover[i]:=true;
   p:=g[i];
   while p<>nil do
    begin
      j:=p^.y;
      q:=link[j];
      if (q=0) then can:=true else find(q);
      if can then
         begin
          link[j]:=i;
          exit;
         end;
      p:=p^.next;
    end;
end;

procedure main;
var i,tmatch:integer;
begin
  for i:=1 to m do
   begin
     fillchar(cover,sizeof(cover),0);
     can:=false;
     find(i);
   end;
  tmatch:=0;
  for i:=1 to n do if link[i]<>0 then inc(tmatch);
  writeln(m+n-tmatch);
end;

begin
{  assign(input,'input.txt');reset(input);}
  init;
{  close(input);}
  main;
end.