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

I got TimeLimited!Help!
Posted by zealot 1 Apr 2003 14:36
Here is my program:

program conference;
const max=1000;
var map:array[1..max,1..max] of boolean;
    link:array[1..max] of longint;
    cover:array[1..max] of boolean;
    n,m,k:longint;
procedure readdata;
var i,j,a,b:longint;
begin
readln(n,m,k);
for i:=1 to k do
 begin
  readln(a,b);
  map[a][b]:=true;
 end;
end;
function find(i:longint):boolean;
var k,p:longint;
begin
find:=true;
for k:=1 to m do
 if map[i][k] and not cover[k] then
  begin
   p:=link[k];link[k]:=i;cover[k]:=true;
   if (p=0) or find(p) then exit;
   link[k]:=p;
  end;
find:=false;
end;
procedure main;
var x:longint;
begin
for x:=1 to n do
 begin
  fillchar(cover,sizeof(cover),0);
  find(x);
 end;
end;
procedure print;
var i,j,step:longint;
begin
step:=0;
for i:=1 to m do
 if link[i]<>0 then inc(step);
writeln(n+m-step);
end;
BEGIN
readdata;
main;
print;
END.