Stable Matchings with Covering Constraints: A Complete Computational Trichotomy

Stable matching problems with lower quotas are fundamental in academic hiring and ensuring operability of rural hospitals. Only few tractable (polynomial-time solvable) cases of stable matching with lower quotas have been identified; most such problems are \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mathsf {NP}$$\end{document}NP-hard and also hard to approximate (Hamada et al. in Algorithmica 74(1):440–465, 2016). We therefore consider stable matching problems with lower quotas under a relaxed notion of tractability, namely fixed-parameter tractability. By cloning hospitals we focus on the case when all hospitals have upper quota equal to 1, which generalizes the setting of “arranged marriages” first considered by Knuth (Mariages stables et leurs relations avec d’autres problèmes combinatoires, Les Presses de l’Université de Montréal, Montreal, 1976). We investigate how a set of natural parameters, namely the maximum length of preference lists for men and women, the number of distinguished men and women, and the number of blocking pairs allowed determine the computational tractability of this problem. Our main result is a complete complexity trichotomy: for each choice of parameters we either provide a polynomial-time algorithm, or an \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mathsf {NP}$$\end{document}NP-hardness proof and fixed-parameter algorithm, or \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mathsf {NP}$$\end{document}NP-hardness proof and \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\mathsf {W}[1]$$\end{document}W[1]-hardness proof. As corollary, we negatively answer a question by Hamada et al. (Algorithmica 74(1):440–465, 2016) by showing fixed-parameter intractability parameterized by optimal solution size. We also classify all cases of one-sided constraints where only women may be distinguished.


Introduction
The Stable Marriage (SM) problem is a fundamental problem first studied by Gale and Shapley [19]. An instance of SM consists of a set M of men, a set W of women, and a preference list for each person ordering members of the opposite sex. We aim to find a stable matching, i.e., a matching for which there exists no pair of a man and a woman who prefer each other to their partners given by the matching; such a pair is called a blocking pair. Gale and Shapley proved [19] that any instance of SM admits at least one stable matching, and gave a polynomial-time algorithm, known as the Gale-Shapley algorithm, to find one. Gale and Shapley also considered the many-to-one extension of SM, known as the Hospitals/Residents (HR) problem. In HR, the two sets H and R that correspond to men and women in the SM problem are residents and hospitals, respectively. Each hospital H ∈ H has an upper quota on the number of residents in R that it can accept. For HR it still holds true that a stable matching always exists, and can be found efficiently.
An extension of HR that is motivated by several real-world applications is the Hospitals/Residents with Lower Quota (HRLQ) problem, where hospitals declare both lower and upper quotas which bound the number of residents they can accept; as before, residents rank hospitals and vice versa. Now it is no longer true that a stable assignment always exists. The possible non-existence of stable assignments motivates the design of algorithms that find an assignment with a minimum number of blocking pairs; this is the task of the HRLQ problem. Indeed, the HRLQ problem and its variants have recently gained quite some interest from the algorithmic community [4,8,16,22,24,26,30,40,44,45]. In his book, Manlove [36,Chapter 5.2] devotes an entire chapter to the algorithmics of different versions of the HRLQ problem.
The reason for this high interest in HRLQ is explained by its importance in several real-world matching markets [17,18,42] such as school admission systems, centralized assignment of residents to hospitals, or of cadets to military branches. Lower quotas are a common feature of such admission systems. Their purpose is often to remedy the effects of under-staffing that are explained by the well-known Rural Hospitals Theorem [20]: as an example, governments usually want to assign at least a small number of medical residents to each rural hospital to guarantee a minimum service level. Minimum quotas are also discussed in controlled school choice programs [13,33,43] where students are divided into a small number of types, and schools set lower bounds for each type. Such models can represent various forms of affirmative actions taken by schools to, e.g., admit a certain number of minority students [13]. Another example is the German university admission system for admitting students to highly oversubscribed subjects, where a certain percentage of study places is assigned according to high school grades or waiting time [43]. But lower quotas may also arise due to financial considerations: for instance, a business course with too few (tuitionpaying) attendees may not be profitable. Certain aspects of airline preferences for seat upgrade allocations can be also modelled by lower quotas [33].
Much of the algorithmic research found that the HRLQ problem (in its different variants) is NP-hard, and thus considered intractable. A common approach then to identify tractable (polynomial-time solvable) cases of HRLQ; this avenue has lead to several beautiful algorithms [16,26,45]. However, restricting to polynomial-time solvability necessarily means (if P = NP) that some original features of HRLQ must be restricted more or less, which may be undesirable in the application. Another approach aimed at addressing the intractability of HRLQ was the design of approximation algorithms. Unfortunately, it turns out that non-trivial approximation algorithms for HRLQ are highly unlikely to exist: Hamada et al. [24] showed that, unless P = NP, no algorithm with approximation guarantee (|H| + |R|) 1−ε can exist for any ε > 0 (which they complement by an algorithm with approximation guarantee (|H| + |R|)). In light of their strong inapproximability bounds, Hamada et al. explicitly suggested to consider a more relaxed notion of tractability for HRLQ, namely, fixed-parameter tractability. They particularly asked whether HRLQ is fixed-parameter tractable parameterized by the minimum number b of blocking pairs over all matchings meeting all lower and upper quota requirements.
In this paper we follow this avenue, and study the fixed-parameter tractability of HRLQ. It allows us to provide a fine-grained analysis of HRLQ, and the design of efficient algorithms for NP-hard variants of HRLQ for small parameter values. Our main focus will be the case of HRLQ when each hospital has unit upper quota. The reason is that by the frequently applied method of "cloning" hospitals, stable instances of HRLQ reduce to the case where each hospital has unit upper quota-and thus we can reduce stable instances of HRLQ to the SM setting with lower quotas. In fact, this is equivalent to the special case of SM where only a subset of women (or, equivalently, men) are distinguished by having also a unit lower quota. From now on, we refer to HRLQ with unit upper quotas as SMC (where C means that we have to cover the women/men who have a unit lower quota), to the special case of SMC with one-sided covering constraints, linking SMC and HRLQ, as SMC-1. So formally, in SMC a set W of women and a set M of men are distinguished, and a feasible matching is one where each person in W ∪ M gets matched. By the Rural Hospitals Theorem [20] we know that the set of unmatched men and women is the same in all stable matchings, so clearly, feasible stable matchings may not exist. Thus, we define the task in SMC as finding a feasible matching with a minimum number of blocking pairs.
Apart from the recent interest in HRLQ, its reduction SMC also serves as a "modern version" of a classical problem first introduced by Donald Knuth. Knuth [31] considered SM with "arranged marriages", which are a set X of man-woman pairs that must be matched with each other. He showed that the Gale-Shapley algorithm can be extended to decide the existence of a stable matching still in time O(n 2 ) for n-person instances, but in case of absence of a stable matching, minimizing the number of blocking pairs is NP-hard. Now in SMC, one does not prescribe any more which woman has to marry which man, but only requires certain women and men to marry without dictating their partner. There is a natural Turing reduction from SMC to the variant considered by Knuth. Coarse analysis into polynomial-time solvable and NP-hard cases has been studied by several researchers [1].
Another motivation for studying the SMC problem comes from the following scenario that we dub Control for Stable Marriage. Consider a two-sided market where each participant of the market expresses its preferences over members of the other party, and some central agent (e.g., a government) performs the task of finding a stable matching in the market. It might happen that this central agency wishes to apply a certain control on the stable matching produced: it may favour some participants by trying to assign them a partner in the resulting matching. Such a behaviour might be either malicious (e.g., the central agency may accept bribes and thus favour certain participants) or beneficial (e.g., it may favour those who are at disadvantage, like handicapped or minority participants). However, there might not be a stable matching that covers all participants the agency wants to favour; thus arises the need to produce a matching that is as stable as possible among those that fulfil our constraints-the most natural aim in such a case is to minimize the number of blocking pairs in the produced matching, which yields exactly the SMC problem. Similar control problems have been extensively studied in the area of social choice for voting systems [7,Chapter 7] and recently also for fair division scenarios [2], but have not yet been considered in connection to stable matchings.

Our Results
We provide an extensive algorithmic analysis of the SMC problem and its special case SMC-1. In our analysis, we examine how different aspects of the input influence the tractability of these problems. To this end, we apply the framework of parameterized complexity, which deals with computationally hard problems and focuses on how certain parameters of a problem instance influence its tractability; for background, we refer to the book by Cygan et al. [11]. We aim to design so-called fixed-parameter algorithms, which perform well in practice if the value of the parameter on hand is small (for the precise definitions, see Sect. 2).
The parameters we consider are -the number b of blocking pairs allowed, -the number |W | of women with covering constraint, -the number |M | of men with covering constraint, -the maximum length Δ W of women's preference lists, and -the maximum length Δ M of men's preference lists.
The choice of each of these parameters is motivated by the aforementioned applications. For instance, we seek matchings where ideally no blocking pairs at all or at least only few of them appear, to ensure stability of the matching and happiness of those getting matched. The number of women/men with covering constraints corresponds, for instance, to the number of rural hospitals for which a minimum quota specifically must be enforced, which we can expect to be small among the set of all hospitals accepting medical residents. Finally, preference lists of hospitals and residents can be expected to be small, as each hospital might not rank many more candidates than the number of positions it has to fill, whereas residents might rank only their top choices of hospitals. We investigate in detail how these parameters influence the complexity of the SMC problem. A parameterized restriction of SMC with respect to the set S = {b, |W |, |M |, Δ M , Δ W } means a (possibly parameterized) special case of SMC where each element of S is either restricted to be some constant integer, or regarded as a parameter, or left unbounded. Intuitively, these different choices for the elements of S correspond to their expected "range" in applications, from very small to mid-range to large (compared to the size of the entire system). By considering all combinations, Here, Δ denotes the maximum length of the preference list of any distinguished person we can flexibly model the whole range of applications mentioned above. We can even cover some cases of master lists, where all men's preference lists are restrictions of the exact same total order over the women, and likewise all women's preference lists are restrictions of the exact same total order over the men. We give a decision diagram in Sect. 7 to show that the presented results indeed cover all restrictions of SMC with respect to {b, |W |, |M |, Δ M , Δ W }. Table 1 summarizes our results on the complexity of SMC. Note that some results are implied directly by the symmetrical roles of men and women in SMC, and thus are not stated explicitly. Here and later, we assume for simplicity that Δ M ≥ 2 and Δ W ≥ 2.
As a special case, we answer a question by Hamada et al. [24] who gave an exponential-time algorithm that in time O(|I | b+1 ) decides for a given instance I of HRLQ whether it admits a feasible matching with at most b blocking pairs; 2 the authors asked whether HRLQ is fixed-parameter tractable parameterized by b. As shown by Theorem 1, SMC-1 and therefore also HRLQ is W[1]-hard when parameterized by b, already in a very restricted setting. Thus, the answer to the question by Hamada et al. [24] is negative: SMC-1, and hence HRLQ, admits no fixed-parameter algorithm with parameter b unless FPT = W[1].

Related Work
There is a dynamically growing literature on matching markets with lower quotas [4,8,[16][17][18]22,24,26,30,40,44,45]. These papers study several variants of HRLQ, adapting the general model to the various particularities of practical problems. However, there are only a few papers which consider the problem of minimizing the number of blocking pairs [17,24]. The most closely related work to ours is the paper by Hamada et al. [24]: they prove that the HRLQ problem is NP-hard and give strong inapproximability results; they also consider the SMC-1 problem directly and propose an O(|I | b+1 ) time algorithm for it.
A different line of research connected to SMC is the problem of arranged marriages, an early extension of SM suggested by Knuth [31]. Here, a set Q of man-woman pairs is distinguished, and we seek a stable matching that contains Q as a subset. Thus, as opposed to SMC, we not only require that each distinguished person is assigned some partner, but instead prescribe its partner exactly. Initial work on arranged marriages [23,31] was extended by Dias et al. [12] to consider also forbidden marriages, and was further generalized by Fleiner et al. [15] and Cseh and Manlove [10]. Despite the similar flavour of the studied problems, none of these papers have a direct consequence on the complexity of SMC.
Our work also fits into the line of research that addresses computationally hard problems in the area of stable matchings by focusing on instances with bounded preference lists [6,27,29,32,41] or by applying the more flexible approach of parameterized complexity [1,3,5,37,38].
Organization After the preliminaries in Sect. 2, we start with the main intractability result in Sect. 3, which answers Hamada et al.'s question. This result shows W[1]hardness of SMC parameterized by b+|W | even when M = ∅ and Δ M = Δ W = 3. Thus, we explore three directions to achieve tractability: (i) to lower b to be a constant, (ii) to lower |W | to be a constant, or (iii) to lower either Δ W or Δ M to 2. We cover the cases (i) and (ii) in Sect. 5, and case (iii) in Sect. 6. In addition, Sect. 4 provides polynomial-time approximation results for HRLQ and SMC, used also in the polynomial-time algorithms of Sect. 5.

Preliminaries
An instance I of the Stable Marriage (SM) problem consists of a set M of men and a set W of women. Each person x ∈ M ∪ W has a preference list L(x) that strictly orders the members of the other party acceptable for x. We thus write L(x) as a vector L(x) = (y 1 , . . . , y t ), denoting that y i is (strictly) preferred by x over y j for each i and j with 1 ≤ i < j ≤ t. A matching M for I is a set of man-woman pairs appearing in each other's preference lists such that each person is contained in at most one pair of M; some persons may be left unmatched by M. For each person x we denote by M(x) the person assigned by M to x. For a matching M, a man m and a woman w included in each other's preference lists form a blocking pair if (i) m is either unmatched or prefers w to M(m), and (ii) w is either unmatched or prefers m to M(w). In the Stable Marriage with Covering Constraints (SMC) problem, we are given additional subsets W ⊆ W and M ⊆ M of distinguished people that must be matched; a matching M is feasible if it matches everybody in W ∪ M . The objective of SMC is to find a feasible matching for I with minimum number of blocking pairs. If only people from one gender are distinguished, then without loss of generality, we assume these to be women; this special case will be denoted by SMC-1.
The many-to-one extension of SMC-1 is the Hospitals/Residents with Lower Quotas (HRLQ) problem whose input consists of a set R of residents and a set H of hospitals that have ordered preferences over the acceptable members of the other party. Each hospital h ∈ H has a quota lower bound q(h) and a quota upper bound q(h), which bound the number of residents that can be assigned to h from below and above. One seeks an assignment M that maps a subset of the residents to hospitals that respects acceptability and is feasible, that is, q(h) ≤ |M(h)| ≤ q(h) for each hospital h. Here, M(h) is the set of residents assigned to some h ∈ H by M. We say that a hospital h is under-subscribed if |M(h)| < q(h). For an assignment M of an instance of HRLQ, a pair {r , h} of a resident r and a hospital h is blocking if (i) r is unassigned or prefers h to the hospital assigned to r by M, and (ii) h is under-subscribed or prefers r to one of the residents in M(h). The task in HRLQ is to find a feasible assignment with minimum number of blocking pairs. Some instances of SMC may admit a master list over women, which is a total ordering L W of all women, such that for each man m ∈ M, the preference list L(m) is the restriction of L W to those women that m finds acceptable. Similarly, we consider master lists over men.
With each instance I of SMC (or HRLQ) we can naturally associate a bipartite graph G I whose vertex partitions correspond to M and W (or R and H, respectively), and there is an edge between a man m ∈ M and a woman w ∈ W (or between a resident r ∈ R and a hospital h ∈ H, respectively) if they appear in each other's preference lists. We may refer to entities of I as vertices, or a pair of entities as edges, without mentioning G I explicitly. For a graph G, we denote its vertex set by V (G) and its edge set by E(G); furthermore, let d G (v) denote the degree of vertex v ∈ V (G) in G. A path P in G is a series of vertices that contains each vertex at most once, with an edge of G connecting any two consecutive vertices of P. With a slight abuse of the notation, we will often identify paths with their edge sets; we will write P ⊆ P to express that P is a subpath of P. A matching in G is a set of edges M ⊆ E(G) such that no vertex in G is adjacent to more than one edges of M; note that a matching in an instance I of SMC indeed corresponds to a matching in the graph G I . For a matching M in G, a path P is called M-alternating, if among any two consecutive edges along P exactly one belongs to M. We will use a few other notions from the theory of matchings about the symmetric difference of matchings, see e.g., the book by Lovász and Plummer [35] for an introduction to this topic.

Parameterized complexity
The framework of parameterized complexity deals with computationally hard problems, examining their complexity in a more detailed way than classical complexity theory. In a parameterized problem problem Π , each input instance I is associated with an integer k called the parameter. An algorithm which decides instances I of Π in time f (k) · |I | O (1) for some computable function f is called a fixed-parameter algorithm. Note that the dependence of the polynomial in the run time is constant, but the dependence on the parameter k can be arbitrary (and is typically exponential). However, if the parameter of a given instance is small, then such an algorithm can be useful in practice even if the overall size of the instance is large.
The class of problems admitting fixed-parameter algorithms is denoted by FPT. To argue that a problem is not in FPT, parameterized complexity provides a hardness theory. For two parameterized problems Π 1 and Π 2 , a parameterized reduction from Π 1 to Π 2 is a function f , computable by a fixed-parameter algorithm, that maps each is a "yes"-instance of Π 1 if and only if (I 2 , k 2 ) is a "yes"-instance of Π 2 , and (ii) k 2 ≤ g(k 1 ) for some function g. The basic class of parameterized intractability is W [1]: proving a problem Π to be W[1]-hard is strong evidence that Π / ∈ FPT. Given some problem Π that is known to be W[1]-hard, a parameterized reduction from Π to some parameterized problem Π implies W[1]-hardness of Π as well.
For more on parameterized complexity, we refer the reader to the book by Cygan et al. [11].

Strong Parameterized Intractability of SMC
This section provides parameterized intractability and inapproximability results for SMC showing the hardness of finding feasible matchings with minimum number of blocking pairs. Namely, we prove SMC-1 to be W[1]-hard parameterized by the number b of blocking pairs we aim for plus the number |W | of distinguished women, even in a very restricted setting.
Observe that any person on P is either a leftist or a rightist. Moreover, the path P, and under the conditions of (b) also the path P i , must contain an edge {x, y} such that x is a leftist and y is a rightist. Let M i be the matching that does not contain {x, y} (where i ∈ {1, 2}). Then both x and y prefer being matched to each other as opposed to their situation in M i (where they may or may not be matched), proving both (a) and (b).

Proof of Theorem 2
We give a reduction from the W[1]-hard Multicolored Clique parameterized by the size of the solution [14]. Let G be the input graph, with its vertex set partitioned into k sets V 1 , . . . , V k ; the task is to find a clique of size k in G containing exactly one vertex from each of the sets V i . We let E i, j denote those edges that run between V i and V j for some 1 ≤ i < j ≤ k. We fix an ordering on the vertices and edges of G that places vertices of V i before vertices of V j whenever i < j (the ordering on the edges of G can be chosen arbitrarily). We will write succ(x) to denote the vertex following x in this ordering, and we let v 1 i and v ∞ i denote the first and last vertices in V i , respectively. Similarly, we write succ({x, y}) for the edge following {x, y}, and we let e 1 i, j and e ∞ i, j denote the first and last edges in E i, j , respectively. We will also write pred(x) and pred({x, y}) for the predecessor of x or {x, y}, respectively. Also, we denote the h-th neighbor of some vertex x as n(x, h). For simplicity, we assume that G has no isolated vertices.
We construct an instance I of SMC as follows; see Figs. 1 and 2 for an illustration. We set the number of blocking pairs allowed for I to be b = 2k + k 2 . Together with the instance I , we will define a stable (but not feasible) matching M s for I as well. If a woman w of I is matched by M s , we will denote the man M s (w) byŵ. Some women will need "dummy" partners in their preference lists: we denote the dummy of w by w. The dummy w will always appear as the last item on w's preference list, and its preference list will always be L( w) = (w).
For each i and j with 1 ≤ i < j ≤ k, we construct an edge selecting gadget G i, j that involves women s i, j and t i, j , together with women a {x,y} , b x→y , and b y→x for each edge {x, y} ∈ E i, j . All women in G i, j are matched by M s except for s i, j , and G i, j contains the manŵ for each of these women w, together with additional dummies b y→x for each {x, y} ∈ E i, j with x preceding y.
For each i ∈ {1, . . . , k}, we also construct a node selecting gadget G i involving women s i , t i , and , and c 1 x , . . . , c b+1 x for each x ∈ V i . The men in G i includeŵ for each woman w of G i except for s i , and additional dummies b 1 and c b+1 x for each x ∈ V i . We define the following sets of women: To define the set W of women in I with covering constraint we let W = S ∪ T ∪ U ; note |W | = 2 k 2 + 2k + k( k 2 + 2k + 1). To finish the definition of I , we define the precise structure of these gadgets as well as the connections between them by the Fig. 1 Node selecting gadget G i in the proof of Theorem 2. Throughout the paper, we use squares for women, circles for men; distinguished persons are denoted by filled squares/circles. The numbering of edges incident to some vertex (or, sometimes, arrows between edges) indicate preferences. Double edges denote edges of the stable matching M s , and dashed edges are those leaving some gadget for any dummy woman w.
where {x, y} = e ∞ i, j and x precedes y, where y = n(x, h) and x precedes y in V (G), where y = n(x, h) and x precedes y in V (G), for any dummy woman w.
preference lists shown in Tables 2 and 3; when not stated otherwise, indices take all possible values. For simplicity, we write b 0 Let us define a master list L W over all women as follows. The first women in L W are those in T , in any ordering. They are followed by women in A, ordered according to the reversed ordering over V (G), that is, a x precedes a y exactly if y precedes x. Next follow women of A , ordered according to the reversed ordering over E(G). Next come women in B ∪ B . To order them, we first order those in B by putting b h x before b y in L W if and only if x precedes y or x = y and h < , then for each edge {x, y} ∈ E(G) with x preceding y, y = n(x, h) and x = n(y, ) we insert b x→y just before b h x , and we insert b y→x just before b y , thus determining the ordering of B ∪ B . After women in B ∪ B come women of C, with c h x preceding c y exactly if h < or h = and x precedes y. We finish the definition of the master list L W by putting all women in S ∪ U at the end of L W in an arbitrary order.
The master list over men is derived from L W by lettingŵ 1 precedeŵ 2 whenever w 1 precedes w 2 in L W , and adding all dummies at the end in an arbitrary order. It is easy to check that the preference lists given in Tables 2 and 3 are indeed compatible with these master lists. This completes the construction of the instance.
We are going to prove that the constructed instance I admits a feasible assignment with at most b blocking pairs if and only if there is a clique of size k in the graph G.
"⇒": Suppose there is a feasible matching M of men to women with at most b blocking pairs. Let G Δ be the symmetric difference M M s . Notice that for each woman s ∈ S, the difference G Δ must contain exactly one maximal path containing s as its endpoint, since the women in S must be matched in M, but are unmatched in M s . Similarly, no path of G Δ can contain a woman in T ∪ U , because these women are matched by M s to their only possible partners, and they must be matched by M as well, since T ∪ U is contained in W . We call a maximal path P in G Δ with an endpoint s in S an improving path. We say that P starts at s and ends at its other endpoint, and we refer to the path starting at s i (or s i, j ) as P i (or P i, j , respectively).
We define the cost of some path P of G Δ as the number of blocking pairs {m, w} for M involving a woman w that appears on P. By Proposition 1, each improving path contains at least one edge that is blocking for M, because no edge can block M s . Therefore, each path in G Δ has cost at least 1.
As there are exactly k + k 2 improving paths (as all women in S must be matched by M), we get a minimum cost of k + k 2 . Note also that the total cost of all paths in G Δ cannot exceed b = 2k + k 2 . Claim 1 is therefore crucial. Claim 1 The following holds for any improving path P of G Δ : (a) P cannot end at a dummy c b+1 x for some x ∈ V (G). (b) P contains an edge {a,â} for some a ∈ A ∪ A that blocks M. (c) If P is not disjoint from G i for some i, then P has cost at least 2.

Proof of Claim 1
To prove (a), suppose for contradiction that P ends at c b+1 x , where x ∈ V i . Clearly, P must contain at least one woman from each of the b + 1 sets To prove (b), let us consider the case when P = P i for some i; the argument goes the same way for the case where P = P i, j for some i and j. If P ends at a x for some x ∈ V i , then a x forms a blocking pair withâ x in M. If P does not end at a woman in A, then it must contain the edge To see (c), first observe that if P is not disjoint from G i , then P ends in G i , simply because of its property that it contains edges from M and M s in an alternating fashion. Therefore, the last woman w on P must be in B ∪ C.
x cannot be on P, as that would imply that b h+1 x is on P, contradicting the choice of w). If, by contrast, w = c for some c ∈ C, then P must end at w by (a), and then c forms a blocking pair with the third man in its preference list (for whom c is the first choice). In either case, w is involved in a blocking pair, which together with the blocking pair guaranteed by (b) implies that P has cost at least 2.
This completes the proof of Claim 1.
Claim 1 proves that for each i ∈ {1, . . . , k} the improving path P i has cost at least 2. Since all the remaining k 2 improving paths have cost at least 1, and the total cost of these paths must be at most b = 2k + k 2 , we get that any path P i (or P i, j ) must have cost exactly 2 (or 1, respectively). Furthermore, it also follows that no other path of G Δ can enter or start in G i , for any i, as that would imply that the number of blocking pairs for M is more than b. In addition, it is not hard to see that G Δ does not contain any cycle, because all cycles in the graph underlying I contain two consecutive edges not in M s . Hence, it follows that the only connected component in G Δ that is not disjoint from G i is P i .
To deal with the possible courses the path P i may take in the graph for some i ∈ {1, . . . , k}, let x i denote the vertex in V i for which {a x i ,â x i } is the blocking edge guaranteed by statement (b) of Claim 1. Observe that P i either ends at a x i or contains the edge {a x i ,b 1 x i }. In either case, we say that P i selects x i from V i ; clearly, there can be only one vertex in V i selected by P i .
Consider now P i, j for some 1 ≤ i < j ≤ k. Recall that P i, j has cost 1. Therefore, statement (b) of Claim 1 proves that the only blocking edge incident to some woman on P i, j must be {a {x,y} ,â {x,y} } for some {x, y} ∈ E i, j . We say that P i, j selects the edge {x, y}; without loss of generality, let us assume that x precedes y. By statement (c) of Claim 1, we also know that P i, j cannot leave G i, j , which means that it can only have cost 1 if it ends at b y→x . In particular, it contains the edges {b x→y ,b y→x } and By the arguments of the previous paragraph, this means that P i must contain the subpath (a . Hence, we obtain that x must be selected by P i . Similarly, from the fact that the edge {b y→x ,b y } where x = n(y, ) is not blocking in M we get that y must be selected by P j .
Thus, we obtain that if an edge is selected by P i, j for some i and j, then its endpoints must be selected by P i and P j . As this must hold for each pair of indices with 1 ≤ i < j ≤ k, we obtain that there must be k 2 edges in G whose endpoints are among the k selected vertices. This can only happen if these edges are the edges of a clique of size k. "⇐": Suppose now that G has a clique of size k formed by the vertices x 1 , . . . , x k , with x i ∈ V i for each i ∈ {1, . . . , k}. Instead of directly defining the required matching M that is feasible and admits at most b blocking pairs, we give M s M as the union of paths P i for i ∈ {1, . . . , k}, and paths P i, j for 1 ≤ i < j ≤ k, defined as follows.
We set P i as the path Similarly, we define It is straightforward to verify that the blocking pairs for M are then the k edges The feasibility of M is trivial; this completes the proof of Theorem 2.
A fundamental hypothesis about the complexity of NP-hard problems is the Exponential Time Hypothesis (ETH), which stipulates that algorithms solving all Satisfiability instances in subexponential time cannot exist [28]. Assuming ETH, the fundamental Clique problem parameterized by solution size k was shown not to admit any algorithm giving the correct answer in time f (k) · n o(k) for all n-vertex instances and any computable function f [9, Thm. 5.4]. The known reduction from Clique to Multicolored Clique does not change the parameter [14]. Finally, in the proof of Theorem 2, an instance of Multicolored Clique with solution size k is reduced to an instance of SMC-1 with parameter b = O(k 2 ).

Corollary 1 Assuming ETH, SMC-1 cannot be solved in time f
for any computable function f , even if there is a master list over men and over women, all preference lists have length at most 3, and each woman in W finds only a single man acceptable.

Theorem 3 Let I be an instance of HRLQ. Let Δ R denote the maximum length of residents' preference lists, and let q Σ denote the sum of lower quota bounds taken over all hospitals in I . There is an algorithm that in polynomial time either outputs a feasible assignment for I with at most (Δ R − 1)q Σ blocking pairs, involving only q Σ residents, or concludes that no feasible assignment exists.
Proof Let H denote the set of hospitals with positive lower quotas. We start by finding an assignment M q that assigns q(h) residents to each hospital h ∈ H , and has the following property: Such an assignment can be obtained as follows. We start from an arbitrary assignment M that assigns q(h) residents to each h ∈ H (if no such assignment exists, then we can stop and reject); such an assignment, if existent, can be found in polynomial time by an algorithm of Hopcroft and Karp [25]. Then we greedily re-assign residents to hospitals of H , one-by-one: at each step, we take a hospital h ∈ H , and if there exists a resident r not assigned to any other hospital in H that h prefers to the least preferred resident r in M(h), then we replace r with r in M(h). If this step cannot be applied anymore, then we arrive at an assignment M q with the desired property ( †).
Given M q , we reduce the upper quotas of each hospital h ∈ H by q(h), set all lower quotas to 0, and delete all residents in R := M q (H ). We then find a stable assignment M s in the resulting instance I ; note that I is an instance of HR, so we can find M s in polynomial time [19]. Finally, we output M out = M s ∪ M q . Clearly, M out is feasible. Also, any blocking pair that M out admits must involve either a hospital from H or a resident from R = M q (H ) by the stability of M s with respect to I . Observe that if some h ∈ H is involved in some blocking pair {r , h} of M out , then we must have r ∈ R . To see this, recall that each resident that is preferred by h to its least preferred resident in M q (h) must be in R because of property ( †), and furthermore, h is under-subscribed in M out (within I ) if and only if h is under-subscribed in M s (within I ). Therefore, we can conclude that each blocking pair for M out must involve some resident in R ; observe that |R | ≤ h∈H q(h) = q Σ . Since each resident in R is incident to at most Δ R − 1 edges not in M out , we also have that M out admits at most If both Δ R and q Σ are constant, then Theorem 3 implies that HRLQ becomes polynomial-time solvable. Indeed, we can use the following simple strategy, depending on the number b of blocking pairs allowed: if b ≥ (Δ R − 1)q Σ , then we apply Theorem 3 directly; if b < (Δ R − 1)q Σ , then we use the algorithm by Hamada et al. [24] running in time O(|I | b+1 ) which is polynomial, since b is upper-bounded by a constant.

Corollary 2 If both the maximum length Δ R of residents' preference lists and the total sum q Σ of all lower quotas is constant, then HRLQ is polynomial-time solvable.
Another application of Theorem 3 is an approximation algorithm that works regardless of whether Δ R or q Σ is a constant. In fact, the algorithm of Theorem 3 can be turned into a (Δ R − 1)q Σ -factor approximation algorithm as follows. First, we find a stable assignment M s for I in polynomial time using the extension of the Gale-Shapley algorithm for the Hospitals/Residents problem. If M s is not feasible, then by the Rural Hospitals Theorem [20], we know that any feasible assignment for I must admit at least one blocking pair; hence, the algorithm presented in Theorem 3 clearly yields an approximation with (multiplicative and also additive) factor (Δ R − 1)q Σ .
To close this section, we also state an analogue of Theorem 3 that deals with SMC: it can handle covering constraints on both sides, but assumes that all quota upper bounds are 1.

pairs, or concludes that I admits no feasible matching.
Proof The proof uses the same ideas as those used in our proof for Theorem 3, so the reader may skip the proof below, which we only include for completeness.
We start by finding an arbitrary matching M that covers each distinguished person (if no such matching exists, then we can stop and reject); such a matching, if existent, can be found in polynomial time by standard flow techniques. We assume, without loss of generality, that each edge in M is incident to some distinguished person. Let us define X = W ∪ M , and let U be the set of those persons x ∈ X whose partner M(x) is also in X .
We proceed by modifying M into a matching M q that covers X and has the following property: If a person x ∈ X \U belongs to a blocking pair {x, y} for M q , then M q (y) ∈ X .
( ) Such an assignment can be obtained as follows. We greedily assign partners to the men and women in X \U , one-by-one: at each step, we take a person x ∈ X \U , and if x forms a blocking pair (with respect to the current matching) with some y that is not the partner of a distinguished person, then we replace the partner of x with y: we add the edge {x, y} to the matching, and delete all the other edges incident to x or y. Observe that the obtained matching is still feasible. If this step cannot be applied anymore, then we arrive at a matching M q with the desired property ( ); note also that each edge in M q is incident to some distinguished person. Given M q , we delete all men and women covered by M q . We then find a stable matching M s in the resulting instance I ; note that I is an instance of Stable Marriage, so we can find M s in polynomial time [19]. Finally, we output M out = M s ∪ M q . Clearly, M out is feasible. Also, any blocking pair that M out admits must involve a person covered by M q due to the stability of M s with respect to I .
We claim that any blocking pair {x, y} involves a person whose partner by M q is distinguished, so either M q (x) ∈ X or M q (y) ∈ X . We can assume that x is covered by M q (because this holds for at least one of x and y). To see the claim, first note that if x is not distinguished, then M q (x) must be distinguished, because each edge of M q contains a distinguished person. Second, if x ∈ X , then either x ∈ U (in which case M q (x) ∈ X ) or M q (y) ∈ X because of property ( ). Therefore, we can conclude that each blocking pair for M out must involve the partner of some distinguished resident. The partners of distinguished women can be incident to at most |W |(Δ M − 1) blocking pairs, and similarly, the partners of distinguished men can be incident to at most |M |(Δ W − 1) blocking pairs, proving the theorem.

SMC with Bounded Number of Distinguished Persons or Blocking Pairs
In Theorem 2 we proved W[1]-hardness of SMC-1 for the case where Δ M = Δ W = 3, with parameter b + |W |. Here we investigate those instances of SMC and SMC-1 where the length of preference lists may be unbounded, but either b, or the number of distinguished persons is constant. First, if the number b of blocking pairs allowed is constant, then SMC can be solved by simply running the extended Gale-Shapley algorithm after guessing and deleting all blocking pairs. This complements the result by Hamada et al. [24].

Observation 1 SMC can be solved in time O(|I | b+1 ), where b denotes the number of blocking pairs allowed in the input instance I .
In Theorem 5 we prove hardness of SMC-1 even if only one woman must be covered. If we require preferences to follow master lists, then a slightly weaker version of Theorem 5, where |W | = 2, still holds.
Proof We present a reduction based on the one from Multicolored Clique given in the proof of Theorem 2. Given some graph G and an integer k as inputs, we are going to re-use the instance I constructed in the proof of Theorem 2. Recall that I has a feasible matching with at most b = k 2 + 2k blocking pairs if and only if G has a clique of size k. Recall also that the set of women that must be covered in I is S ∪ T ∪ U ; here we denote this set by W I . We define a modified instance I of SMC as follows. For each w ∈ W I , we create a forcing gadget F w which apart from w contains the newly introduced women a w , b w , c w , d w and men a w , b w , c w , d w . We also add the distinguished woman s, who must be covered in I , and the unique man t in L(s). See Fig. 3 for an illustration.
Let n(w) denote the unique man acceptable for some w ∈ W I in I . Additionally, we let Y = {a w , c w | w ∈ W I }, and we write [Y ] for an arbitrarily fixed ordering of the elements of Y . The preferences of the newly introduced men and women, as well as the modified preferences of those agents that find them acceptable, is given below. Here, again, indices take all possible values, and w can be any woman in W I . We let I contain all other women and men defined in I , having the same preferences as in I .
We will show that I has a feasible matching with at most b blocking pairs if and only if I has such a matching; this clearly proves the theorem.
First observe that any feasible matching M for I contains the edge {s, t}. Thus, if some woman y in Y is not matched by M to her first choice, then {y, t} is blocking in M . Consider now F w for some w ∈ W I . It is straightforward to check that if M (w) = n(w), then there are at least two blocking pairs incident to a woman in F w . Indeed, assume first that {t, a w } is the only blocking pair in F w ; this quickly implies M (c w ) = d w and M (a w ) = a w , which in turn leads to {d w , d w } blocking M , a contradiction. Second, assume that {t, a w } does not block M ; from this follows M (a w ) = b w and we have that {b w , w} is a blocking pair for M . Now either {t, c w } is blocking (in which case our claim holds), or we get M (c w ) = d w , which implies that {d w , w} blocks M , again a contradiction. Now, let W i be the women in G i that must be covered in I , i.e., Consider the number β i of blocking pairs for M that involve a woman either in the gadget G i or in a gadget F w for some w ∈ W i . On the one hand, if some w ∈ W i is not matched by M to n(w), then β i ≥ 2 because of the blocking pairs in F w . On the other hand, if each w ∈ W i is matched by M to n(w), then using the arguments of the proof for Theorem 2, we again know β i ≥ 2 because of the blocking pairs in G i . Also, β i = 2 can only be achieved if and F s i ), implying at least one blocking pair in G i in addition to those in F u h i . Analogously, let β i, j denote the number of blocking pairs for M that involve a woman either in the gadget G {i, j} or in a gadget F w for some w ∈ {s i, j , t i, j }. Then either β i, j ≥ 2, or we know that M (w) = n(w) for both women w ∈ {s i, j , t i, j }; in this case, from the proof of Theorem 2 we get β i, j ≥ 1. However, supposing that M has at most b = 2k + k 2 blocking pairs, it follows that β i = 2 and β i, j = 1 must hold for each i ∈ {1, . . . , k} and each i, j with 1 ≤ i < j ≤ k, respectively.
Along the same lines as in the proof of Theorem 2, it can also be verified that β i, j = 1 for each pair of indices i, j can only be achieved if M M s contains a path in each gadget G i . From M (w) = n(w) for each w ∈ W i \{s i } we get that such a path contains at least one blocking pair. This implies M (s i ) = n(s i ), as otherwise we would end up with β i ≥ 3 because of the blocking pairs incident to women of F s i .
Altogether, we have proved that M (w) = n(w) for each w ∈ W I . Hence, the restriction of M to I yields a feasible matching for I that admits at most b blocking pairs.
For the other direction, suppose that I has a feasible matching M. Then it is easy to see that adding the edges {a w , b w }, {b w , c w }, {c w , d w }, and {d w , a w } for each w ∈ W I together with the edge {s, t} to M yields a feasible matching for I that contains exactly the same number of blocking pairs in I as M does in I .

even if there is a master list over men as well as one over women
Proof The proof is very similar to the one for Theorem 5, so we will only sketch it. Again, we are going to re-use the instance I constructed in the proof of Theorem 2, and construct a modified instance I of SMC, adding only two new women z 1 and z 2 and two men m 1 and m 2 to I . We append z 1 and z 2 , in this order, to the master list over women, and similarly, we append m 1 and m 2 to the master list over men. We define the women to be covered in I as z 1 and z 2 .
Again, we denote the set of women to be covered in I by W I , and we denote by n(w) the unique man acceptable for some w ∈ W I in I . The preferences of the newly introduced men and women, as well as the modified preferences of those agents that find them acceptable, is given below (here, [W I ] ≺ denotes the ordering of W I given by the master list). We let I contain all other women and men defined in I , having the same preferences as in I .
Arguing analogously as before in the proof of Theorem 5, one can show that I has a feasible matching with at most b blocking pairs if and only if I has such a matching; this suffices to prove the theorem.
To contrast our intractability results, we show next that if each of the four parameters |W |, |M |, Δ W , and Δ M is constant, then SMC becomes polynomial-time solvable. Our algorithm relies on the observation that in this case, the number of blocking pairs in an optimal solution is at most (Δ M −1)|W |+(Δ W −1)|M | by Theorem 4. Note that for instances of SMC-1, Theorem 7 yields a polynomial-time algorithm already if both |W | and Δ M are constant.

SMC with Preference Lists of Length at Most Two
In this section we investigate the computational complexity of SMC where the maximum length of preference lists is bounded by 2 on one side. This restriction leads to important tractable special cases: we obtain both polynomial-time algorithms and fixed-parameter tractability results for various parameterizations.
Let I be an instance of SMC with underlying graph G. Let M s be a stable matching in I , and let M 0 and W 0 denote the set of distinguished men and women, respectively, unmatched by M s . Furthermore, let M 0 and W 0 denote the set of all men and women, respectively, unmatched by M s . A path P in G is called an augmenting path, if M s P is a matching, and either both endpoints of P are in M 0 ∪ W 0 , or one endpoint of P is in M 0 ∪ W 0 , and its other endpoint is not distinguished. This definition ensures that for an augmenting path P, the set of distinguished men and women that are matched in M s P strictly contains the set of distinguished men and women matched in M s . 3 We will call an augmenting path P masculine or feminine if it contains a man in M 0 or a woman in W 0 , respectively; if P is both masculine and feminine, then we call it neutral. If P is not neutral, then we say that it starts at the (unique) person from M 0 ∪ W 0 it contains, and ends at its other endpoint.

Covering Constraints on One Side
Here we deal with the SMC-1 problem where only women need to be covered. We first give a polynomial-time algorithm for SMC-1 when each man finds at most two women acceptable, and then show NP-hardness of SMC-1 for instances where each woman finds at most two men acceptable. We start by considering the special case of SMC-1 where Δ M ≤ 2.
Theorem 8 There is a polynomial-time algorithm for the special case of SMC-1 where each man finds at most two women acceptable.

High-Level Description
The main observation behind Theorem 8 is that if Δ M ≤2, then any two augmenting paths starting from different women in W 0 are almost disjoint, namely they can only intersect at their endpoints. Thus, we can modify the stable matching M s by selecting augmenting paths starting from each woman in W 0 in an almost independent fashion: intuitively, we simply need to take care not to choose paths sharing an endpoint-a task which can be managed by finding a bipartite matching in an appropriately defined auxiliary graph. To ensure that the number of blocking pairs in the output is minimized, we will assign costs to the augmenting paths. Roughly speaking, the cost of an augmenting path P determines the number of blocking pairs introduced when modifying M s along P (though certain special edges need not be counted); hence, our problem reduces to finding a bipartite matching with minimum weight in the auxiliary graph.
To present the algorithm of Theorem 8 in detail, we start with the following properties of augmenting paths which are easy to prove using that Δ M ≤ 2: Proposition 2 Suppose Δ M ≤ 2. Let P 1 and P 2 be augmenting paths starting at women w 1 and w 2 , respectively.
(a) If w 1 = w 2 , then P 1 and P 2 are either vertex-disjoint, or they both end at some If there is an edge {m, w} of G (with m ∈ M and w ∈ W) connecting P 1 and P 2 , then m ∈ M 0 and P 1 or P 2 must end at m. (c) If w 1 = w 2 and P is the maximal common subpath of P 1 and P 2 starting at w 1 , then either V (P 1 ) ∩ V (P 2 ) = V (P), or P 1 and P 2 both end at some m ∈ M 0 and V ( With a set P of edges (typically a set of augmenting paths) where M s P is a matching, we associate a cost, which is the number of blocking pairs that M s P admits. A pair {m, w} for some m ∈ M and w ∈ W is special, if m ∈ M 0 and w is the second (less preferred) woman in L(m). As it turns out, such edges can be ignored during certain steps of the algorithm; thus, we define the special cost of P as the number of non-special blocking pairs in M s P.  P 2 ). Consider now the case when {m, w} connects P 1 and P 2 . By Proposition 2, this implies that one of the paths, say P 1 , ends at m ∈ M 0 (and w lies on P 2 ). Clearly, {m, w} is not blocking in M s P 1 , by the stability of M s . If, on the one hand, w is the first choice of m, then {m, w} is blocking in M s P 2 exactly if it is blocking in M s (P 1 ∪ P 2 ). If, on the other hand, {m, w} is special, then it cannot be blocking in M s (P 1 ∪ P 2 ), but it might be blocking in M s P 2 . Putting all these facts together, the lemma follows immediately.
We are ready to provide the algorithm, in a sequence of four steps.
Step 1: Computing all augmenting paths By Proposition 2, if we delete M 0 from the union of all augmenting paths starting at some w ∈ W 0 , then we obtain a tree. Furthermore, these trees are mutually vertex-disjoint for different starting vertices of W 0 . This allows us to compute all augmenting paths in linear time, e.g., by an appropriately modified version of a depth-first search algorithm (so that only augmenting paths are considered). During this process, we can also compute the special cost of each augmenting path in a straightforward way.
Step 2: Constructing an auxiliary graph Using the results of the computation of Step 1, we construct an edge-weighted single bipartite graph G path = (U , V ; E) as follows.
To define the vertices of G path we set U := W 0 and V := M 0 ∪ {w | w ∈ W 0 }, so for each woman w ∈ W 0 we create a corresponding new vertex w . The edge set E contains an edge {w, w } for each w ∈ U , as well as an edge {w, m} whenever w ∈ U , m ∈ M 0 and there exists an augmenting path with endpoints w and m. We define the weight of an edge {w, w } as the minimum special cost c min w of any augmenting path starting at w and not ending in M 0 , and we define the weight of an edge {w, m} with w ∈ U and m ∈ M 0 as the minimum special cost of any augmenting path with endpoints w and m.
Step 3: Computing a minimum weight matching We compute a matching M P in G path covering U and having minimum weight; this can be done in polynomial time by, e.g., the Hungarian method [34]. Observe that the matching M P corresponds to a set of augmenting paths P = {P w | w ∈ W 0 } that are mutually vertex-disjoint by Proposition 2. Recall that the special cost of P w is the weight of the edge in M P incident to w.
Step 4: Eliminating blocking special edges In this step, we modify P iteratively. We start by setting P act = P. At each iteration we modify P act as follows. We check whether there exists a special edge {m * , w * } that is blocking in M s P act . If yes, then notice that m * is not matched in M s P act , because {m * , w * } is special and thus m * ∈ M 0 . Let P be the path of P act containing w * . We modify P act by truncating P to its subpath between its starting vertex and w * , and appending to it the edge {m * , w * }. This way, {m * , w * } becomes an edge of the matching M s P act . The iteration stops when there is no special edge blocking M s P act . Note that once a special edge ceases to be blocking in M s P act , it cannot become blocking again during this process, so the algorithm performs at most |M 0 | iterations. For each w ∈ W 0 , let P * w denote the augmenting path in P act covering w at the end of Step 4; we define P * = {P * w | w ∈ W 0 } and output the matching M s P * .
This completes the description of the algorithm; we now provide its analysis.
Lemma 2 M sol := M s P * is a feasible matching for I , and the number of blocking pairs for M sol is at most the weight of M P .
Proof Consider the situation when the iteration in Step 4 deals with a special edge {m * , w * } blocking in P act . Notice that since w * is the second woman in L(m * ) (by the definition of a special edge), and since {w * , m * } is blocking in M s P act , we know that m * is unmatched in M s P act , that is, m * does not lie on any of the augmenting paths in P act . From this follows that the augmenting paths in P act , and hence in P * , remain mutually vertex-disjoint. Therefore, M sol is indeed a matching. As it covers W 0 , and no augmenting path ends at a woman in W \W 0 , matching M sol is feasible. Clearly, Step 4 ensures that there are no blocking special edges in M sol . Note that when the algorithm modifies P w for some w ∈ W 0 , at most one new blocking pair may arise with respect to M s P act , and from the stability of M and Proposition 2 it follows that such an edge must be a special edge (incident to the man at which P w ends before its modification). This means that Step 4 gets rid of all blocking special edges without introducing any non-special blocking edges. Hence, we obtain that the cost of P * w is at most the special cost of P w , for each w ∈ W 0 . By Lemma 1, the number of blocking pairs that M sol admits is at most the sum of the costs of all augmenting paths in P * ; this finishes the proof.
To show that our algorithm is correct and M sol is optimal, by Lemma 2 it suffices to prove that the weight of M P is at most the number of blocking pairs in M opt , where M opt denotes an optimal solution in I . To this end, we are going to define a matching covering W 0 in G path whose weight is at most the number of blocking pairs in M opt .
Clearly, M s M opt contains an augmenting path Q w covering w for each w ∈ W 0 . If some Q w ends at a man m ∈ M 0 , then clearly no other path in M s M opt can end at m. So let us take the matching M Q in G path that includes all pairs {m, w} where Q w ends at m ∈ M 0 for some w ∈ W 0 . Also, we put {w, w } into M Q if Q w does not end at a man of M 0 . Note that M Q is indeed a matching.
It remains to show that the weight of M Q is at most the number of blocking pairs in M opt . By definition, the weight of M Q is at most the sum of the special costs of the paths Q w for every w ∈ W 0 . By Lemma 1, any non-special blocking pair in M s Q w remains a blocking pair in M s ( w∈W 0 Q w ), and hence in M opt as well. Hence, there is a matching in G path with weight at most the number of blocking pairs in an optimal solution, implying the correctness of our algorithm. As the algorithm runs in polynomial time, Theorem 8 follows.
By contrast to Theorem 8, if men may have preference lists of length 3, then SMC-1 (and hence SMC) is NP-hard even if each woman finds at most two men acceptable.  The preference lists of I are given in Table 4. Let the set of women with covering constraints be and set the number of blocking pairs allowed to be |V (G)| + k. We are going to prove that I admits a feasible matching with at most |V (G)| + k blocking pairs if and only if there is a vertex cover of size k in the graph G. "⇒": Let M be a feasible matching with at most |V (G)| + k blocking pairs. We say that the cost of some gadget G x (or G {x,y} ) is the number of edges blocking M Table 4 Preference lists of women and men in the proof of Theorem 9 where x precedes y, When not stated otherwise, indices take all possible values which are incident to some man of G x (or G {x,y} , respectively.) We will prove that the set S of vertices x for which G x has cost at least 2 is a vertex cover of G.
x form a blocking pair for M. Moreover, if the woman a x→y is unmatched in M for some y, then {a x→y , b h x } is also a blocking pair in M (where y = n(x, h)), and implies a cost of at least 2 for G x . Therefore, we can observe that if x / ∈ S, then a x→y must be matched by M to b x→y for each neighbor y of x in G.
However, for any {x, y} ∈ E(G), M must match s {x,y} either to b x→y or to b y→x (because s {x,y} is contained in W ), which means that x ∈ S or y ∈ S. This proves that S is indeed a vertex cover for G. Moreover, the number of vertices in S can be at most k, since each G x with x ∈ S has cost at least 2, each G x with x / ∈ S has cost at least 1, and the total cost of all gadgets cannot exceed our budget |V (G)| + k.
"⇐": Given a vertex cover S of size at most k for G, we define a matching M with the desired properties. Namely, for each x ∈ S we set M(s x ) = d x is unmatched by M, and thus forms a blocking pair with b . Observe also that d x is not contained in any blocking pair. Finally, for some {x, y} ∈ E(G), let us assume y ∈ S (since S is a vertex cover, it contains x or y). We set M(s {x,y} ) = b y→x and M(a x→y ) = b x→y . Note that a x→y gets her first choice, so it cannot be involved in a blocking pair. Although a y→x is unmatched by M, we know that it cannot form a blocking pair with b y where x = n(y, ), because y ∈ S and hence b y is assigned her first choice by M. Thus, no man or woman of some edge gadget participates in a blocking pair, and therefore we obtain that the total number of blocking pairs for M is exactly |V (G)| + k.
Since M is feasible, the theorem follows.

Covering Constraints on Both Sides
Let us now investigate the complexity of SMC with covering constraints both for men and women. If we restrict the maximum length of preference lists on both sides to be at most 2, SMC becomes linear-time solvable. To see this, observe that by max(Δ W , Δ M ) ≤ 2, the underlying graph G must be a collection of paths and cycles. Thus, we can process the connected components of G one by one. Applying dynamic programming on each component K , we can determine the minimum number b K of blocking pairs for any matching that is feasible for K , together with a matching M K for K that admits b K blocking pairs. If K is a path, then this can be done in a straightforward manner, traversing the edges of K one by one in linear time. If K is a cycle, then we can pick any edge e of K , guess whether it is contained in M K , or blocks M K , or neither of the two; we can then process the remainder of K (which is a path) taking into account our guess for e. To compute the minimum number of blocking pairs that a feasible matching admits in our instance, we can simply sum up the values b K over each connected component K of G. Hence, we arrive at the following.

Observation 2 Instances of SMC with max(Δ W , Δ M ) ≤ 2 are linear-time solvable.
Recall that the case where Δ W = 2 and Δ M = 3 is NP-hard by Theorem 9, even if there are no distinguished men to be covered. However, switching the roles of men and women in Theorem 8, we obtain that if there are no women to be covered, then Δ W ≤ 2 guarantees polynomial-time solvability for SMC. This raises the natural question whether SMC with Δ W ≤ 2 can be solved efficiently if the number of distinguished women is bounded. Next we show that this is unlikely, as the problem turns out to be NP-hard for |W | = 1. Proof We present a reduction from the following special case of Exact-3-Cover. We are given a set U = {u 1 , . . . , u n }, a family S of subsets S 1 , . . . , S m of U , each having size 3, such that each element of U occurs in at most three sets of S. The task is to decide whether there exists a collection of n/3 sets in S whose union covers U ; such a collection of subsets is called an exact cover for U . This problem is NP-complete [21,GT2]. We construct an equivalent instance I of SMC as follows.
The set W of women in I contains the women s j , p 1 j , p 2 j , p 3 j , and q j for each j ∈ {1, . . . , m}, women x and y, as well as two women a i, j , b i, j for each element u i contained in S j for each j ∈ {1, . . . , m}. The men defined in I arep 1 j ,p 2 j ,p 3 j ,q j , and t j for each j ∈ {1, . . . , m}, a man c i for each u i ∈ U , a manb i, j for each element u i contained in S j for each j ∈ {1, . . . , m}, plus one additional manŷ.  Table 5. Note that since each subset S j contains three elements, and each element u i is contained in at most three subsets from S, we get that all men except forŷ have a preference list of length at most 3, as promised. To finish the construction, we set the number of allowed blocking pairs to be b = 2m + 2n/3 + 1.
We denote by ind( j, h) the index i for which u i is the h-th element in S j . When not stated otherwise, indices take all possible values We claim that I admits a feasible matching with at most b blocking pairs if and only if (U , S) is a "yes"-instance of Exact-3-Cover.
"⇒": Suppose that M is a feasible matching for I with at most b blocking pairs. Clearly, as x is distinguished, M must contain the edge {x,ŷ}. Thus, {y,ŷ} is blocking in M. Second, since t j is distinguished for each j ∈ {1, . . . , m}, we get that M matches t j either to q j or to p 1 j , which in turn implies that either {q j ,q j } or { p 1 j ,p 1 j } blocks M, leading to m additional blocking pairs for M. Third, consider now any man c i , i ∈ {1, . . . , n}: as c i is distinguished, we know M(c i ) = b i, j for some j such that S j contains u i . In this case, {b i, j ,b i, j } is also a blocking pair for M, yielding n blocking pairs of such form. Thus, if b U denotes the number of blocking pairs among the edges {b i, j ,b i, j } for indices i and j with u i ∈ S j , then we get b U ≥ n. This adds up to m + b U + 1 ≥ m + n + 1 blocking pairs so far.
Let us define the set E j of those edges that are incident to s j ,p 3 j ,p 2 j , orp 1 j , but not to p 1 j for some j ∈ {1, . . . , m} ; note that these sets are pairwise disjoint, and none of them contains any of the (possibly) blocking edges mentioned in the previous paragraph.
Let k be the number of indices j for which E j contains no blocking pairs for M; we call such indices (and the subsets S j corresponding to them) selected. The m − k non-selected indices clearly correspond to at least m − k blocking pairs for M (each contained in E j for some j).
Suppose now that j is selected. Then, since {s j ,ŷ} is not blocking, we get M(s j ) =p 3 j , sinceŷ prefers s j to its partner x. This implies that M( p 3 j ) =p 2 j , as oth- Summing up the blocking pairs identified so far, we know that M admits at least 1 + m + (m − k) + max(n, 3k) blocking pairs. Using that this must be upper-bounded by b = 1 + m + n + (m − n/3), it is easy to show that only k = n/3 is possible. This yields that there exist exactly n/3 selected indices, and for all such indices j all the edges {b i, j ,b i, j } for which u i ∈ S j are blocking with respect to M. Moreover, we also must have b U = n, as otherwise the number of blocking pairs would exceed b.
However, observe that for each i ∈ {1, . . . , n}, there must exist some j with u i ∈ S j for which the pair {b i, j ,b i, j } is blocking in M (because c i is distinguished), implying that for each u i ∈ U there must exist some selected S j that contains u i . Since there are exactly n/3 selected sets in S, we get that they form an exact covering of U .
"⇐": Suppose that (U , S) is a "yes"-instance of Exact-3-Cover. Let J be the set of indices describing a solution, meaning that the subsets S j ∈ S with j ∈ J form an exact covering of U ; clearly, |J | = n/3. We define σ (i) as the unique index j in J for which u i ∈ S j . We define a feasible matching M for I with exactly b blocking pairs as follows (indices take all possible values, if not stated otherwise).
It is easy to check that M indeed is feasible, and the blocking pairs it admits are exactly the pairs {y,ŷ}, ∈ J , and {s j ,ŷ} for each j / ∈ J . This proves the lemma.
Contrasting Theorem 10, we establish fixed-parameter tractability of the case Δ W ≤ 2 with three different parameterizations. Considering our five parameters, the relevant cases (whose tractability or intractability does not follow from our results obtained so far) are as follows, assuming Δ W ≤ 2 throughout. Since letting the number b of blocking pairs and the number |W | of distinguished women to be unbounded (while assuming Δ W ≤ 2) results in NP-hardness by Theorem 9, in order to obtain fixed-parameter tractability, we need to take either b or |W | as a parameter. However, taking only |W | as a parameter is not likely to result in tractability, as the case |W | = 1 is still NP-hard by Theorem 10. Thus we need to take either |M | or Δ M as an additional parameter. Altogether, this results in the following parameterizations of the SMC problem, each case subject to the assumption Δ W ≤ 2: -taking b as the parameter, -taking |W | + |M | as the parameter, and -taking |W | + Δ M as the parameter. We show fixed-parameter tractability for each three of these parameterizations. The first two parameterizations can be dealt with an algorithm whose properties are stated in Theorem 11 (see also Corollary 3), while the third parameterization will be considered by Theorem 12. Theorem 11 There is a fixed-parameter algorithm for the special case of SMC where each woman finds at most two men acceptable (i.e., Δ W ≤ 2), parameterized by the number |W 0 | + |M 0 | of distinguished men and women left unmatched by some stable matching.
Let M opt denote an optimal solution for our instance I such that M s M opt contains the minimum number of edges; recall that M s is a fixed stable matching for I . Without loss of generality, we can further assume that there does not exist another optimal solution M such that (i) M has the same number of common edges with M s as M opt , and (ii) for each man m, either M (m) = M opt (m) or m prefers M (m) to M opt (m). 4 Indeed, as long as such a "superior" matching M exists, we can simply pick that instead of M opt , until this is no longer possible. This way, we eventually end up with an optimal matching that satisfies our requirement.
We denote by b the number of blocking pairs in M opt .

High-Level Description
Let us remark first that simply guessing the optimal partners for each woman in W 0 and then using the polynomial-time algorithm presented in Sect. 6.1 (after exchanging the roles of men and women) does not work, since that algorithm heavily relies on the assumption that we start with a stable matching. In fact, the main difficulty to overcome is that feminine and masculine augmenting paths may "interact" in the sense that certain blocking pairs introduced by a feminine augmenting path can be "eliminated" (i.e., made non-blocking again) by an appropriately chosen masculine path. Therefore, we apply the following strategy. In Phase I, we find all feminine paths (as well as all cycles) in M s M opt , and in Phase II we proceed with choosing the masculine paths carefully. Note that in Phase I it does not suffice to find a cheapest set of feminine augmenting paths, since we may not be able to eliminate as many blocking pairs afterwards as it is possible after an optimal choice of feminine paths. Instead, we need to find the exact feminine augmenting paths (and cycles) present in M s M opt ; this can be accomplished by guessing certain properties of M opt . In Phase II, the main obstacle is that we do not know which blocking edges should be eliminated in an optimal solution, nor can we guess these edges efficiently. We deal with this problem by guessing the sets of those men in M 0 whose augmenting paths in M s M opt contribute to the elimination of a blocking pair; this information allows us to find these masculine paths. Finally, we apply the algorithm of Theorem 8. For the detailed description of our algorithm, we need a couple of simple observations and some additional notation. We begin with the following implications of the fact that each woman finds at most two men acceptable.

Proposition 3
Suppose Δ W ≤ 2. Let P 1 and P 2 be two augmenting paths.
(a) If P 1 and P 2 start at some w ∈ W 0 through the same edge, then one of them is a subpath of the other. (b) If P 1 and P 2 start at different women w 1 and w 2 , respectively, and P 1 and P 2 are not disjoint, then the set of their common vertices induces a suffix of either P 1 or P 2 (or both); their first common vertex is a man. (c) If P 1 and P 2 are disjoint and e is an edge incident to both, then one of the paths starts or ends at a women w, and e connects w with a man on the other path.
Observations (a) and (b) of Proposition 3 immediately suggest that feminine paths are easy to find, since once we decide which edge to start with, all possible augmenting paths lead in the same direction; the only difficulty arises in deciding when to stop. Observation (c) describes the limited ways in which two augmenting path can interact; we next look closer at such interactions.
We say that an edge f = {m, w} of G (with m ∈ M and w ∈ W) is dependent if it connects two different connected components K 1 and K 2 of M s M opt and, in addition, it holds that M s K 1 admits more blocking pairs than M s (K 1 ∪ K 2 ). We will say that f , and with a slight abuse of the notation, also K 1 relies on K 2 . We say that f has type A, if w is the endpoint of K 2 (which is a path), f connects w with a man m on K 1 that prefers M s (m) to w, and w to M opt (m), and w is unmatched by M s and prefers M opt (w) to m; f has type B, if w is the endpoint of K 1 (which is a path), unmatched by M opt , and f connects w with a man m on K 2 that prefers M opt (m) to w, and w to M s (m).
See Fig. 5 for an illustration of the above definitions.  (H ∪ K ), it also must have an endpoint in K . Let w and m be the woman and the man connected by f , respectively. We distinguish now between two cases. First, let us assume that w is contained in K . Since m is not contained in K , and w can only be connected to two men, it follows that the degree of w in K is at most (and hence exactly) 1. Since each connected component of M s M opt is either a cycle or a path, this implies that K is a path with w being one of its endpoints.

Lemma 3 Let
Since Second, let us assume that w is contained in a connected component K of H . As in the previous case, we quickly get that K must be a path, with w being an endpoint of K . Since f blocks M s H , we know that w is matched by M s but is unmatched by M opt . The stability of M s implies also that w prefers M s (w) to m.
Regarding m, the fact that f blocks M s H implies that m prefers w to M s (m). However, since f ceases to be blocking in M s (H ∪K ), we get that m prefers M opt (m) to w. This proves that f has type B.
We are now ready to present our algorithm, which is a branching algorithm: throughout its course, we make several "guesses" for which all possibilities have to be explored. When certain guesses turn out to be trivially wrong, such guesses are discarded, and we might not explicitly mention this in the algorithm. (In Step 1, we describe such issues in detail for illustration, but later we omit them.) Phases I and II consist of Steps 1-5 and Steps 6-8, respectively.
Step 1: Guessing the first edges of feminine augmenting paths First, for each w ∈ W 0 with |L(w)| = 2, we guess the edge of M opt incident to w. This results in at most 2 |W 0 | possibilities, all of which must be explored. Naturally, we discard those guesses where the edges {w, M opt (w)}, w ∈ W 0 , do not form a matching. From now on we assume that we know M opt (w) for each w ∈ W 0 .
Additionally, we delete those edges {m, w} for which w ∈ W 0 and w prefers M opt (w) to m. Such edges are neither needed in M opt , nor can they block any matching that contains all the edges {w, M opt (w)}, w ∈ W 0 , guessed in this step.
Before proceeding to Step 2, we state an important lemma about augmenting paths. Hence, M opt Q admits at least b + 1 blocking pairs. Since Q is a maximal path in M s M opt and M s is stable, Proposition 1 implies that there must be an edge along Q that blocks M opt . Obviously, there is no edge on Q that blocks M s , since M s is stable. Hence, modifying M opt by switching the edges of M s and M opt along Q decreases the number of blocking edges among the edges of Q. However, the same operation increases the total number of blocking pairs (from b to at least b + 1), thus we get that there must exist at least two edges that become blocking only as a result of this switch along Q. In other words, there exist at least two edges that are blocking in M opt Q but are not blocking in M opt . By Lemma 3 we obtain that these edges must be dependent edges relying on Q. 5 By the definition of a type A edge, at most one type A edge can rely on Q (as only one endpoint of Q can be a woman unmatched by M s , and this woman may be incident to at most one edge outside Q), so we get that at least one of these dependent edges relying on Q must have type B.

Lemma 4 Each connected component of M s M
Let us call the man endpoint of a type B dependent edge a joiner; by the previous paragraph, Q contains at least one joiner. Our aim is to fix an "outer-most" joiner m on Q. However, for technical reasons we also have to take into account a special case where some man m lying on Q, called the looper for Q, fulfils the following properties: (i) one endpoint of Q is a woman w that is adjacent to m in G but prefers M s (w ) to m , and (ii) m prefers w to M s (m ) but prefers M opt (m ) to w . 6 Now, we choose a man m that is either a joiner or the looper for Q so that the following holds: if m splits Q into two subpaths Q 1 and Q 2 with Q 1 containing M opt (m), then V (Q 1 )\{m} contains neither joiners nor the looper for Q.
Case for a Joiner First, let us assume that m is a joiner. In this case, there might be several women who form a dependent edge of type B with m, so let w denote the one that is most preferred by m. Let f be the edge {m, w}, and let P be the path of M s M opt that has w as its endpoint. We illustrate these concepts in Fig. 6.
We claim that M f = M opt (Q 1 ∪{ f }) = (M opt Q 1 )∪{ f } is an optimal solution. Observe that M s M f can be obtained from M s M opt by deleting Q and substituting P by the path P + f + Q 2 where the plus sign means concatenation. Let x denote First, M f is clearly feasible, since x is not distinguished (by our assumption that Q is non-augmenting). Next, suppose that some edge e is blocking in M f but is not blocking in M opt . It is easy to see that by our choice of w, e cannot be incident to w or m. As only vertices in Q 1 ∪ { f } are matched differently in M f as in M opt , we obtain that one endpoint of e must lie on Q 1 . Using the stability of M s , we also get that the other endpoint of e must lie either on a connected component of M s M opt other than Q or on Q 2 . In the former case, Lemma 3 implies 7 that e is a dependent edge. By our choice of m, e cannot be of type B, hence by Lemma 3, e must have type A, and thus it is incident to x which must be a woman not covered by M s . In the latter case, supposing that the man endpoint m of e lies on Q 1 we quickly get that it must be the looper for Q. To see this, first note that the only woman that m can be adjacent to on Q 2 must be the common endpoint of Q 2 and Q (by Δ W ≤ 2); let w denote this woman. Second, since e blocks M f but it does not block M opt , we know that m prefers w to M s (m ), but prefers M opt (m ) to w . Third, since m prefers w to M s (m ), the stability of M s implies that w is matched by M s and w prefers M s (w ) to m . Hence, m is indeed the looper for Q, contradicting our choice of m. Thus, we know that it must be the woman endpoint of e that lies on Q 1 . Since the two endpoints of Q 1 are m ∈ M and x, by Δ W ≤ 2 we obtain that the woman endpoint of e lying on Q 1 can only be x, which therefore must be a woman not covered by M s . In either case, we can conclude that there can only exist at most one such edge e (because x has degree at most 2 in G). So the number of edges that are blocking in M f but not blocking in M opt is at most one.
Furthermore, since f is a dependent edge of type B, by definition we know that m prefers y = M opt (m) to M s (m), and hence, y must prefer M s (y) to m (as otherwise {m, y} would be blocking in M s , which is not possible). Note that, in particular, M s (y) exists and Q 1 contains at least two edges. By Proposition 1, Q 1 must contain at least one edge that blocks M opt , and this edge is not blocking in M f , simply because any edge of Q 1 that blocks M opt but be an edge contained in M s and hence in M f . Thus, the number of edges blocking M f cannot be more than b. Hence, M f is an optimal

Case for a Looper
Let us now assume that m = m is the looper for Q. In this case let f be the edge connecting m to the woman endpoint w of Q that is matched by M s ; it is easy to see that w is the endpoint of Q 2 as well. See Fig. 7 for an illustration. Let us again define M f = M opt (Q 1 ∪ { f }). As in the previous case, it is immediate that M f is feasible. Arguing similarly as before and using that Q 1 does not contain any joiners, we get that any edge that blocks M f but does not block M opt can only be a type A dependent edge incident to the (woman) endpoint x of Q 1 that is not m . Hence, there can be at most one edge blocking M f but not M opt . From this point on, we can use the same reasoning as in the previous case to arrive at the conclusion that M f is an optimal solution that has more edges common with M s than M opt , a contradiction. This proves the first statement of our lemma.
Let us prove (b) now. Suppose that K 1 and K 2 are two connected components of M s M opt such that K 1 relies on K 2 via an edge f = {w, m} of type B. By the definition of a type B edge, we know that K 1 is a path with an endpoint that is a woman covered by M s , so its other endpoint is either a woman not covered by M s , or a man covered by M s . Thus, K 1 cannot be a masculine path, so by the first statement of the lemma, it is feminine. It remains to show that if K 2 is a path, then it is feminine. Assume for contradiction that K 2 is a non-feminine path Q in M s M opt and some other path P in M s M opt relies on Q via a type B edge f . In this case we can argue exactly as above to show that there must exist an optimal matching M f (defined the same way as we did while proving the first statement of the lemma) for which M s M f contains less edges than M s M opt , a contradiction.
To show (a), suppose that K 1 and K 2 are two connected components of M s M opt such that K 1 relies on K 2 via an edge f = {w, m} of type A. By the definition of a type A edge, the woman endpoint w of f is unmatched in M s , and K 2 is a path that has w as an endpoint. Also, m is the second choice of w and M opt (w) is the first choice of w. Hence w ∈ W 0 is not possible, as in that case the edge f would have been deleted in Step 1 of the algorithm. Furthermore, since K 2 is an M s -alternating path with an endpoint in W 0 , the other endpoint of K 2 cannot be a woman in W 0 . Hence, K 2 is not a feminine augmenting path. Since we already know that K 2 is an augmenting path, (a) follows. Consider now any woman w ∈ W 0 . Let us define a candidate path for w as an augmenting path that starts through the edge {w, M opt (w)}. Observe that P opt w itself is a candidate path for w. Furthermore, although we cannot determine P opt x directly, Proposition 3 implies that there exists a unique maximal candidate path A w for w that contains P opt w as a subpath. We can compute A w easily: starting from the edge {w, M opt (w)}, we can build A w by adding edges of M s and edges not in M s in an alternating manner, always appending a new edge to the last vertex of the current subpath of A w . Observe that after an addition of an edge of M s , the resulting subpath of A w ends at a woman, and thus Δ W ≤ 2 implies that there exists at most one edge that we can add to our path. This shows the uniqueness of A w .
Step 2: Finding cycles in M s M opt We make one more guess for each w ∈ W 0 by guessing whether P opt w relies on some cycle of M s M opt or not; this again yields 2 |W 0 | possibilities. If P opt w relies on some cycle C, then by Proposition 3, both P opt w and C can be found in time O(|P opt w | + |C|) as follows. We compute the longest possible candidate path A w for w. Since P opt w relies on cycle C, the last person on A w must be a woman x incident to an edge {x, m} for which m is already on A w . Then the subpath of A w between m and x together with the edge {x, m} form the cycle C. For an illustration, see Fig. 8. Proof Let C be a cycle in M s M opt . By the stability of M s , no edge of C blocks the matching M opt C. Since M opt C has more edges in common with M s than M opt does, we know by the choice of M opt that there must be an edge incident to C that is blocking in M opt C but is not blocking in M opt . By Lemma 3, such an edge must be a dependent edge e relying on C. This proves that there are no cycles in M s M opt without augmenting paths relying on them.
By Lemma 4 we know that dependent edges of type A rely on (masculine) paths, 8 so e must have type B. From this, Lemma 4 yields that all paths relying on a cycle must be feminine paths. Hence, Step 2 indeed finds all paths that rely on some cycle, together with the cycles that these paths rely upon, which (as pointed out above) means that Step 2 finds all cycles of M s M opt , proving our claim.
Step 3: Finding neutral paths In this step, for each w ∈ W 0 we guess whether w lies on a neutral path in M s M opt , yielding at most 2 |W 0 | possibilities. Clearly, if w lies on a neutral path, then by Proposition 3, P opt w is the maximal candidate path starting with the edge {w, M opt (w)}, that is, P opt w = A w .
Step 4: Finding feminine paths relying on other feminine paths In this step, we find all feminine paths that rely on some other feminine path; note that feminine paths that do not depend on other feminine paths will be taken care of by Step 5.
In Step 4, we first guess for each w ∈ W 0 whether P opt w relies on another feminine path, and if so, we also guess on which one. This means at most |W 0 | possibilities for each w ∈ W 0 , a total of |W 0 | |W 0 | possibilities.
Supposing that, according to our guesses, P opt w relies on P opt y for some w and y in W 0 , we can find P opt w easily as follows. Consider the maximal candidate paths A w and A y for w and y, respectively. We know that P opt w and P opt y are disjoint, but supposing that our guesses were made correctly, Lemma 4 implies that they are connected by a dependent edge f of type B relying on P opt y . Hence, A w contains P Notice that this method only enables us to locate P opt w but not P opt y ; we only know that P opt y must contain the man m incident to f , but we do not know where P opt y ends. To remind us that P opt y contains m, we store m as an obligatory man for y.
Step 5: Finding all remaining feminine paths In this step, we find all feminine paths that rely neither on a cycle, nor on another feminine path. To do so, we will use a surprisingly simple method. Intuitively, it makes sense to construct augmenting paths to be as short as possible, since the longer such a path gets, the more opportunities arise for a blocking pair to appear along the way. This intuition is almost entirely correct, if no other path (or cycle) relies on the augmenting path P opt w we are looking for: it turns out that P opt w is either indeed the shortest possible, or if this is not the case, then we can "get rid of" only one blocking pair by constructing a longer augmenting path-and this, too, we can keep as short as it is possible, by stopping whenever we encounter a decrease in the number of blocking pairs along the augmenting path. In the case when some other path relies on P opt w , we need to be somewhat more careful, and take into account the obligatory men defined in Step 4. After this high-level explanation, let us define Step 5 formally. Let W r be the set of those women w ∈ W 0 for which P opt w has not been found yet (that is, where P opt w is not neutral, and it does not rely on any other path or cycle in M s M opt ). Let us fix any woman w ∈ W r . With any candidate path Q for w, we associate a matching M Q = (M opt P opt w ) Q; we can think of M Q as the matching that results from replacing P opt w with Q in the symmetrical difference of M s and the solution. Let us state a few useful properties of candidate paths and their associated matchings.

Proposition 4
The following holds for any candidate path Q for w: To see that M Q is a matching, let K −w denote the union of all connected components of M s M opt except for P opt w . Then M opt P opt w = M s K −w is a matching. But as K −w is vertex-disjoint from Q, from (a) we get that M Q = (M s K −w ) Q must be a matching too. The properties of Q described in (c) show also that M Q is feasible. Now, we define two candidate paths for w as follows: -First, we let Q 1 w be the shortest candidate path for w that contains all obligatory men for w. In particular, if there are no obligatory men for w, then Q 1 w is the shortest candidate path for w; see Fig. 9 for an illustration. -Second, let Q 2 w be the shortest candidate path containing Q 1 w such that M s Q 2 w admits less blocking pairs than M s Q 1 w . Such a path, however, may not exist, in which case we leave Q 2 w undefined. Proof First observe that for any w ∈ W r , if the guesses made by the algorithm are correct, then P opt w contains Q 1 w as a subpath. To see this, recall that if the guesses made in Step 4 of the algorithm are correct, then P opt w indeed must contain all obligatory men for w. Since P opt w is a candidate path for w, it indeed must contain Q 1 w . w contains all the obligatory men for w, which contradicts our assumption of case (i).
In case (ii), let w e and m e be the woman and man endpoint of e, respectively; we assumed w e = x. By Δ W ≤ 2, w e can only be adjacent to both V (Q)\V (Q 1 w ) and V (Q 1 w ) if either w e = w, or Q and also P opt w ends at w e . In the former case, m e ∈ V (P Note that since m ∈ V (P opt x ), f cannot be of type A (by the definition of a type A edge), so it must be of type B. However, Lemma 4 tells us that a type B edge relies either on a cycle or on a feminine path, but as P opt x is neither of the two, we arrive at a contradiction.
Thus, we get w ∈ V (P Thus, by Δ W ≤ 2 we know that w = y, and since f blocks M f but not M opt , we also get that m must be the second choice of w . Hence f is volatile, proving our claim.
By Claim 4, there can be at most one edge that is blocking in M f but not in M opt . Since f is an edge that blocks M opt but not M f , we get that M f is an optimal matching. Moreover, either M f has more common edges with M s than M opt , or m is the last man on P opt x , in which case every man has the same partner in M f as in M opt except for m who is better off in M f than in M opt . This contradicts our choice of M opt .
For any volatile edge f we can decide in linear time if there exists a masculine augmenting path disjoint from F that contains the woman endpoint w of f , but not f itself. Indeed, we can build such a path starting from w by taking edges not in M s and edges in M s in an alternating manner; by Δ W ≤ 2 and since we need to start with an edge different from f , we always have at most one possibility to pick our next edge. This process may or may not result in a masculine augmenting path, but if it does, then the path is unique, proving the following claim.
is a relevant edge in M opt , then M s M opt must contain all paths in P elim f . Since there may be several volatile edges blocking in M s F, we cannot determine the relevant ones among them by simply guessing them. Instead, we only guess the elimination sets for all relevant edges. Clearly, these sets must be pairwise disjoint subsets of M 0 , so guessing them results in at most (|M 0 | + 1) |M 0 | possibilities. Let us denote by R 1 , . . . , R the guessed elimination sets.
Step 8: Computing cheapest elimination paths For each set R i ⊆ M 0 with i = 1, . . . , that, according to our guesses made in Step 7, forms the elimination set for a volatile edge relevant in M opt , we determine some volatile edge f incident to F that is blocking in M s F and whose elimination set is exactly R i . Namely, we pick an edge f among all such edges in a way that the number of blocking pairs in M s (F ∪P elim f ) is as small as possible. Let f i be the volatile edge chosen this way, and let P elim = 1≤i≤ P elim f i .
Step 9: Computing remaining masculine paths We define M r = M 0 \(R 1 ∪ · · · ∪ R ) as the set of distinguished men that are neither covered by M s nor contained in any of the sets R 1 , . . . , R . For each such m we are going to compute an augmenting path P m disjoint from F such that the number of edges that block M s (F ∪ m∈M r P r ) but not M s F is minimized. We set P r = {P m | m ∈ M r }.
To compute P r , we use the algorithm of Theorem 8 with some modifications.
Step 9. 1 We compute all augmenting paths that start at a man m ∈ M r and are disjoint from F. For each such augmenting path P we define a set C(P) containing those edges that block M s (F ∪ P) but not M s F, and are either non-volatile or have a woman endpoint in F; we define the contributing cost of P as |C(P)|.
Step 9. 2 We construct the auxiliary graph G path = (U , V ; E) as follows: we set U = M r and V = W 0 ∪ {m | m ∈ M r }. The edge set E contains an edge {m, m } for each m ∈ U , as well as an edge {m, w} whenever m ∈ U , w ∈ W 0 and there exists an augmenting path disjoint from F with endpoints m and w. We define the weight of an edge {m, m } as the minimum contributing cost c min m of any augmenting path starting at m and not ending in W 0 , and we define the weight of an edge {m, w} with m ∈ U and w ∈ W 0 as the minimum contributing cost of any augmenting path with endpoints m and w, disjoint from F.
Step 9. 3 We compute a minimum weight matching M P in G path covering U the same way as in the algorithm of Theorem 8; let P denote the set of augmenting paths corresponding to the edges of the matching M P . Note that the paths in P are pairwise disjoint, by the construction of G path and because M P is a matching in G path .
Step 9. 4 We eliminate all volatile edges that block M s (F ∪ P) but not M s F and are not incident to F. We modify P iteratively. We start by setting P act = P. At each iteration we modify P act as follows. We check whether there exists a volatile edge {m * , w * } with w * ∈ W 0 that is not incident to F, and blocks M s (F ∪ P act ) but not M s F. If yes, then notice that w * is not matched in M s (F ∪ P act ), because m * is the second choice for w * . Let P be the path of P act containing w * . We modify P act by truncating P to its subpath between its starting vertex and m * , and appending to it the edge {m * , w * }. This way, {m * , w * } becomes an edge of the matching M s (F ∪ P act ). The iteration stops when there is no volatile edge disjoint from F blocking M s (F ∪ P act ) but not M s F. Note that once a volatile edge ceases to be blocking in M s (F ∪ P act ), it cannot become blocking again during this process, so the algorithm performs at most |W 0 | iterations. For each m ∈ M r , let P m denote the augmenting path in P act covering m at the end of this step; we set P r := {P m | m ∈ M r }.
Step 9.5 Finally, we output the matching M out = M s (F ∪ P elim ∪ P r ).
It is straightforward to verify that the number of guesses made are bounded by a function of |W 0 | + |M 0 |, and all computations in a branch can be performed in time polynomial in the size |I | of the instance, yielding a fixed-parameter algorithm with parameter |W 0 |+|M 0 |. It remains to prove the correctness of the proposed algorithm.
To this end, we first prove a simple observation. Proof Let m * and w * be the man and woman connected by e. By e ∈ C(P m ) it does not block M s F, so we only need to show that e blocks M s (F ∪ P r ). Suppose for contradiction that e does not block M s (F ∪ P r ). Then it must clearly be adjacent to some path P x , x ∈ M r . By Δ W ≤ 2 we know that w * is the endpoint of one of these paths, w * ∈ W 0 , and since e blocks M s (F ∪ P m ) but not M s (F ∪ P r ) we also get that m * must be the less preferred choice of w * ; this yields that e is volatile. However, as e is not incident to F (because it connects P m and P x ), this contradicts e ∈ C(P m ).
Let m 1 and m 2 be two distinct men in M r ; we will show C(P m 1 ) ∩ C(P m 2 ) = ∅. Assuming otherwise, let e be an edge in C(P m 1 ) ∩ C(P m 2 ). Then e does not block M s F but blocks both M s (F ∪ P m 1 ) and M s (F ∪ P m 2 ). Hence e connects P m 1 with P m 1 , and thus blocks M s P m 1 and M s P m 2 as well, contradicting Proposition 6. Thus, Then, by the definition of edge-weights in G path , we get that there exists a matching M in G path with weight at most m∈M r |C(P m )| ≤ c that covers U = M r . Thus, the matching computed by the algorithm in Step 9.3 has weight at most c as well, yielding that the set P r of augmenting path corresponding to this matching is such that m∈M r |C(P m )| ≤ c , that is, their total contribution cost is at most c . From this, Claim 6 below implies that there can be at most c edges that block M s (F ∪ P r ) but not M s F.

Claim 6
If an edge e blocks M s (F ∪ P r ) but not M s F, then e ∈ C(P m ) for some m ∈ M r .
Proof Let m * and w * be the man and woman connected by e. Clearly, e is adjacent to some path in P r .
First, suppose that e is adjacent to only one path P m where m ∈ M r . Then e must block M s (F ∪ P m ) as well. In that case, to prove e ∈ C(P m ) we only need to show that either w * is in F or is e is non-volatile. Suppose for contradiction that e is volatile and w * is not in F. However, as a result of Step 9.4, there can be no volatile edge that blocks M s (F ∪ P r ), unless it is incident to F. Hence, we must have that m * is in F, and since e blocks M s (F ∪ P m ), we get that m * prefers w * to its partner in M s (F ∪ P m ), which is the same partner he has in M s F. However, this yields that e blocks M s F as well: since w * ∈ W 0 and w * is not in F, she is unmatched in M s F. Hence, we arrive at a contradiction, proving e ∈ C(P m ).
Second, suppose that e connects two paths P m 1 and P m 2 where m 1 and m 2 are distinct men in M r . By Δ W ≤ 2, we know that w * is an endpoint of one of these paths; without loss of generality, we may assume that w * is an endpoint of P m 1 . Since P m 1 is a masculine augmenting path, we get w * ∈ W 0 . Now, we know that e blocks M s (F ∪ P m 1 ∪ P m 2 ), so it must also block M s (F ∪ P m 2 ), because w * is unmatched in M s (F ∪ P m 2 ) and m * has the same partner in M s (F ∪ P m 2 ) as in M s (F ∪ P m 1 ∪ P m 2 ). Again, e cannot be volatile as a result of Step 9.4, yielding that e is contained in C(P m 2 ).
This proves the optimality of P r as stated by the lemma.
Next we state the following useful lemma. Proof First observe that the statement of the lemma is obviously true for any edge e that is incident to at most one of Q and Q . So suppose that e connects Q with Q . Since both Q and Q are masculine augmenting paths and Δ W ≤ 2, by Proposition 3 we know that e connects the woman endpoint w of one of these paths with a man m on the other path; moreover, w must be unmatched by M s as it is the endpoint of a masculine augmenting path. Let Q w be the path (either Q or Q ) that contains w, and let Q m be the one containing m.
We are going to show paths that minimizes the number of edges that block M s (F ∪ P r ) but not M s F, we know that there are at most c r such edges. This in turn shows that there can be at most c r edges that block M out but not M out P r , as implied by Claim 9. This proves the optimality of M out .

Claim 9
If e is an edge that blocks M out but not M out P r , then e blocks M s (F ∪ P r ) but not M s F.

Proof
Since M out = M s (F ∪ P r ∪ P elim ) and M out P r = M s (F ∪ P elim ), we have that if e does not have an endpoint in P elim , then the claim follows immediately.
So suppose that e is incident to a path Q ∈ P elim f i for some i ∈ {1, . . . , }. As e blocks M out but not M out P r , the other endpoint of e must be contained in a path P m for some m ∈ M r . Since Q and P m are the only connected components of M s M out that e is adjacent to, the condition of our claim yields that e blocks M s (Q ∪ P m ) but not M s Q, and we only need to show that e blocks M s P m , which is directly implied by Lemma 11, proving our claim.
This finishes our proof of correctness for Theorem 11.
As each augmenting path contains at least one edge that blocks M opt , the number of blocking pairs admitted by M opt is at least (|W 0 |+|M 0 |)/2. Thus, we get Corollary 3.

Corollary 3
The special case of SMC where each woman finds at most two men acceptable (i.e., Δ W ≤ 2) is fixed-parameter tractable for parameter b.
It remains to deal with the third among the parameterizations we have to consider. So let us turn our attention to the complexity of the SMC with Δ W ≤ 2 where we take |W | + Δ M as the parameter.

Theorem 12
There is a fixed-parameter algorithm for the special case of SMC where each woman finds at most two men acceptable (i.e., Δ W ≤ 2), and the parameter is |W | + Δ M , the number of distinguished women plus the maximum length of men's preference lists.
It turns out that Theorem 12 can be proved by a modified version of the algorithm described above to prove Theorem 11. In fact, we start with applying Steps 1 to 6. However, we can no longer apply Step 7, because now |M | can be unbounded, and thus guessing the elimination sets would not yield a fixed-parameter tractable algorithm. To circumvent this problem, we rely on an observation stated by Lemma 12 which shows that "almost all" volatile edges that are blocking in M s F are relevant edges, and thus have to be eliminated. This allows us to efficiently guess the set of relevant volatile edges, leading us to a fixed-parameter tractable algorithm. Hence, instead of guessing only the elimination sets (that is, the man endpoints of the elimination paths) we can now guess the exact set of edges that the optimal solution eliminates, so in fact the modified algorithm can be viewed as a more simple approach.
Let E vol denote the set of all volatile blocking edges in M s F, and let {m, w} ∈ E vol for some man m. We say that {m, w} is loose, if -both M s and M opt assign a partner to m, m prefers M s (m) to w, and w to M opt (m), and -M opt (m) is not distinguished.

Lemma 12
All loose edges in E vol are relevant, and at most (Δ M − 1)|W | edges in E vol are not loose.
Proof First suppose that {m, w} for some man m is loose. Since {m, w} is volatile, we have that m is the less preferred man acceptable to w, and since {m, w} is blocking in M s F, we know that w is unmatched in M s F.
For the sake of contradiction, let us suppose that {m, w} is not relevant, meaning that it is still blocking in M opt . In this case, w must be unmatched in M opt too. We define a matching M obtained from M opt by modifying only the partner of m to be M (m) = w and, i.e., M = (M opt \{{m, M opt (m)}}) ∪ {{w, m}}. Observe that M is indeed a matching, because w was unmatched in M opt . It is also feasible, because only M opt (m) becomes unmatched by this modification, and M opt (m) is not distinguished (by the definition of a loose edge). Furthermore, while {m, w} is not blocking in M , the only edge that might be blocking in M but not in M opt is the edge adjacent to M opt (m) but not to m, if existent (because both m and w are better off in M than in M opt ). Hence, M is also an optimal matching. It should also be clear that it has the same number of common edges with M s as M opt . Note also that each man has the same partner in M as in M opt except for m who is better off in M than in M opt . This contradicts our choice of M opt , proving that {m, w} must indeed be relevant.
To prove the second part of the lemma, let us consider any edge {m, w} ∈ E vol with m ∈ M. Again, w must be unmatched in the matching M s F, since otherwise {m, w} would not block it (because m is the less preferred man in w's preference list). By contrast, {m, w} cannot block M s , which can be explained in three different ways, giving rise to the following three cases: In Case A, by {m, w} ∈ M s , the edge {m, w} must be contained in an augmenting path of M s F, with w being an endpoint (since w is not matched in M s F). In Case B, M s matches w to its first choice, say x, so the edge {w, x} must be contained in an augmenting path of M s F, with w being an endpoint. Thus, in both cases we know that w is an endpoint of a feminine augmenting path of F. However, Cases A and B exclude each other, because in Case A the augmenting path ending at w contains the edge connecting w to her second choice, while in Case B it connects w to her first choice. Since there are at most |W | feminine augmenting paths, it follows that the number of such edges {m, w} ∈ E vol where the conditions of Cases A or B hold is at most |W |.
In Case C, let us first observe that m gets matched in M s F. Indeed, if this were not the case, then m would be the man endpoint of a feminine augmenting path, with the last edge contained in M s ; however, this is not possible (simply because feminine paths start with women and with edges not in M s ). Because F is a collection of connected components of M s M opt , with m contained in F, it is clear that the partner of m in M s F is the same as his partner in M opt . Thus, M opt (m) exists, and since {m, w} blocks M s F, we know that m prefers w to M opt (m). Therefore, either {m, w} is a loose edge, or M opt (m) is distinguished; in the latter case, we say that {m, w} belongs to this distinguished woman. Now, observe that all edges belonging to some woman z ∈ W are adjacent to M opt (z), and M opt (z) is adjacent to at least two edges not belonging to z: namely, the edges {M opt (z), z} and {M opt (z), M s (M opt (z))}. Hence, at most Δ M − 2 edges may belong to z, implying that there are at most (Δ M − 2)|W | edges in total belonging to distinguished women. Taking into account all three cases, we get that there are at most (Δ M − 1)|W | edges in E vol that are not loose.
Let us now describe our algorithm proving Theorem 12 in detail. This algorithm starts with Steps 1 to 6 (as given for Theorem 11), and then applies Steps 7 and 8 below. The last step of our algorithm is Step 9 from the algorithm for Theorem 11.
Step 7 : Guessing the relevant edges To determine which edges among those volatile edges that block M s F are relevant, we first compute the set E loose of all loose edges in E vol . Notice that when checking some edge {m, w} ∈ E vol , we already know M opt (m): since m lies on a path or cycle of F, it gets matched in M s F to the same woman as in M opt . Therefore, checking whether {m, w} is loose is straightforward.
After determining all loose edges (which are all relevant by Lemma 12), we guess the remaining set of relevant edges in E vol \E loose . By Lemma 12, this yields at most 2 (Δ M −1)|W | possibilities, and in the branch where our guess is correct, we obtain the set E rel of all relevant volatile edges blocking in M s F.
Step 8 : Computing cheapest elimination path This step is a simplification of Step 8 of the algorithm for Theorem 11. By Lemma 9, for each f ∈ E rel the elimination paths in P elim f (determined in Step 6) are all contained in M s M opt ; let P elim = ∪ f ∈E rel P elim f .
Step 9 : Computing remaining masculine paths Let M r denote the set of distinguished men in M 0 not covered by any of the elimination paths in P elim . For each m ∈ M r we compute an augmenting path P m disjoint from F such that the number of edges that block M s (F ∪P r ) but not M s F is minimized, where P r is the union of all paths P m , m ∈ M r . We accomplish this with the exact same method as in Step 9 of the algorithm for Theorem 11. Finally, we output the matching M out = M s (F ∪ P elim ∪ P r ).
Note that the number of guesses made in Steps 1 to 6 are bounded by a function of |W 0 |, and the guesses made in Step 7 result in at most 2 (Δ M −1)|W | possibilities. Since all computations in a branch can be performed in time polynomial in the size |I | of the instance, we obtain a fixed-parameter algorithm with parameter |W | + Δ M . It remains to prove its correctness.

Proof of Theorem 12
The proof is a straightforward adaptation of our proof for Theorem 11. The only difference is that instead of finding some elimination paths that eliminate the necessary number of relevant volatile edges blocking in M s F, our algorithm now directly finds all of the relevant edges among those volatile edges that block M s F, together with the corresponding elimination paths; this is a consequence of Lemma 12 and the definition of Step 7 . As Step 8 can also be viewed as a simplification of Step 8 as defined for the algorithm for Theorem 11, it can be verified that the exact same arguments that prove the correctness of Step 8 in our algorithm for We remark that if a certain restriction of SMC where one of the values v ∈ S is a constant k proves to be NP-hard or W[1]-hard with some parameterization, then it is easy to see that the same hardness result also holds for the case where v ≥ k (and all other assumptions are the same). We refer to the "reflection" of a result by adding the postfix 'R' to its name (so Theorem xR denotes the reflection of Theorem x); here by reflection we mean the statement obtained by switching the roles of men and women Theorem 11 also imply the correctness of Step 8 for our algorithm for Theorem 12 in a straightforward manner.

Discussion
We provided a systematic study of the computational complexity of Stable Marriage with Covering Constraints. Our main result is a complete computational complexity trichotomy into polynomial-time solvable cases, NP-hard and fixed-parameter tractable cases, and NP-hard and W[1]-hard cases, for all possible combinations of five natural parameters: -|M |: the number of distinguished men, -|W |: the number of distinguished women, -Δ M : the maximum length of preference lists for men, -Δ W : the maximum length of preference lists for women, and b: the number of blocking pairs allowed.
As a special case, we solved a problem by Hamada et al. [24]. Figure 10 provides a decision diagram showing that our results indeed fully determine the computational complexity of SMC with respect to the set S = {b, |W |, |M |, Δ M , Δ W } of possible parameters. Going through this decision diagram should convince the reader that any parameterized restriction of SMC with respect to the set S is classified as either polynomial-time solvable (P) or NP-hard, and in the latter case, either fixed-parameter tractable (FPT), or W[1]-hard with the given parameterization (if any). In particular, when we provide parameterized results, this means that the parameterized restriction of SMC in question is NP-hard without parameterization.
Given the strong polynomial-time inapproximability bounds, as well as the parameterized intractability results of this paper, we pose as an open question whether fixed-parameter approximation algorithms can beat either of these obstacles for solving SMC.
Another challenge for future research is to investigate possible adaptations of the proposed algorithms to the Hospitals/Residents model (note that, naturally, all our hardness results for SMC-1 apply to the HRLQ problem), or to a setting where ties are allowed in the preference lists.