If I understood the question correctly, it should be possible to generate a cardinality-maximal matching of the initial graph efficiently, by either using the so-called Hungarian method or modelization as a network flow problem. Once the cardinality-maximal matching has been found, there must be an equal number of unmatched nodes in either partition, which can be matched using additional edges at will.
In other words, if M
is the cardinality of a cardinality-maximal matching in the original graph and |X|=|Y|
holds, then at at least M-|X|
edges have to be added in order to have a perfect matching contained in the graph.