POJ 3692 (Hungarian algorithm)

Source: Internet
Author: User

[Delphi]
Program p1_2;
Const
Maxn = 200;
 
Var
N, m, l, I, j, k, ans, x, y: longint;
B: array [1 .. 400] of boolean;
Map: array [1 .. 400, 1 .. 400] of boolean;
A: array [1 .. 400] of longint;
Function find (x: longint): boolean;
Var
I, j: longint;
Begin
For I: = 1 to m do
If not (B [I]) and (map [x, I]) then
Begin
B [I]: = true;
If a [I] = 0 then begin a [I]: = x; exit (true); end;
If find (a [I]) then begin a [I]: = x; exit (true); end;
End;
 
Exit (false );
End;
Begin
I: = 1;
Read (n, m, l );
While (n + m + l> 0) do
Begin
Ans: = 0;
Fillchar (a, sizeof (a), 0 );
Fillchar (map, sizeof (map), true );
For k: = 1 to l do
Begin
Read (x, y );
Map [x, y]: = false;
End;
For k: = 1 to n do
Begin
Fillchar (B, sizeof (B), false );
If find (k) then inc (ans );
End;
Writeln ('case', I, ':', n + m-ans );
Inc (I );
Read (n, m, l );
End;
End.

Hungarian algorithm: www.2cto.com
B [] indicates whether the current point for finding the staggered P has been connected. a [] indicates the point before a certain point.
The two points graph in this question is the largest group (each point is connected to each other). The two points graph can be regarded as the largest independent set of the supplementary graph (each point is not connected to each other )......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.