Strongly Matchable

Decide whether an even-order graph admits a perfect bipartite matching for every balanced partition of its vertices.

Hard9GraphMathCombinatoricsDynamic programmingNo attempts yetTime limit3sMemory limit512 MB

Problem

GG is a simple undirected graph with nn vertices, and its vertex set and edge set are written V(G)V(G) and E(G)E(G). Two edges of GG are adjacent if they share a vertex. Two vertices of GG are adjacent if they share an edge, and that edge joins the two vertices. An edge and an endpoint of that edge are incident. A subset MM of E(G)E(G) is a matching of GG if no two edges in MM are adjacent, and MM is a perfect matching if every vertex of GG is incident to exactly one edge of MM. So a matching MM is perfect if and only if M=n/2|M| = n/2.

A maximum matching, a matching with the largest number of edges, can be found in polynomial time, so the existence of a perfect matching in GG is decided in polynomial time. Two more questions can be asked about the existence of a perfect matching.

  • Given one partition of V(G)V(G) into SS and TT with S=T=n/2|S| = |T| = n/2, does GG have a perfect matching in which every edge joins a vertex in SS and a vertex in TT?
  • For every partition of V(G)V(G) into SS and TT with S=T=n/2|S| = |T| = n/2, does GG have a perfect matching in which every edge joins a vertex in SS and a vertex in TT?

Hall's marriage theorem gives a condition that characterizes the answer to the first question. Let GG' be the spanning subgraph of GG obtained by deleting every edge whose endpoints both lie in SS or both lie in TT, so that V(G)=V(G)V(G') = V(G) and E(G)E(G') is the set of all edges of E(G)E(G) with one endpoint in SS and the other endpoint in TT. Then GG has the required perfect matching between SS and TT if and only if GG' has a perfect matching. By Hall's theorem, GG' has a perfect matching if and only if N(X)X|N(X)| \ge |X| holds for every subset XX of SS, where N(X)N(X) is the neighborhood of XX, the set of all vertices in TT adjacent to some vertex of XX. A polynomial-time maximum matching algorithm answers this question in polynomial time as well.

Is there an efficient algorithm for the second question? A graph whose answer to the second question is yes is called strongly matchable. That is, GG is strongly matchable if, for every partition of V(G)V(G) into SS and TT with S=T=n/2|S| = |T| = n/2, GG has a perfect matching in which each edge joins one vertex in SS and one vertex in TT. For example, the graph in figure 1 (a) is strongly matchable. Up to symmetry there are only three partitions, and each of them admits a perfect matching: M={(1,4),(2,5),(3,6)}M = \{(1,4), (2,5), (3,6)\} for S={1,2,3}S = \{1, 2, 3\} and T={4,5,6}T = \{4, 5, 6\}, M={(1,3),(2,5),(4,6)}M = \{(1,3), (2,5), (4,6)\} for S={1,2,4}S = \{1, 2, 4\} and T={3,5,6}T = \{3, 5, 6\}, and M={(1,3),(2,5),(6,4)}M = \{(1,3), (2,5), (6,4)\} for S={1,2,6}S = \{1, 2, 6\} and T={3,4,5}T = \{3, 4, 5\}. The graph in (b) is not strongly matchable, because there is no perfect matching between S={1,2,4}S = \{1, 2, 4\} and T={3,5,6}T = \{3, 5, 6\}. Write a program that decides whether a graph with an even number of vertices is strongly matchable.

(a)(b)

Figure 1: the graph in (a) is strongly matchable, and the graph in (b) is not.

Input

The first line contains the number of vertices nn and the number of edges mm. nn is even, 2n1002 \le n \le 100, and 1mn(n1)/21 \le m \le n(n-1)/2. Each of the next mm lines contains one edge, given as the two vertices uu and vv that the edge joins. The vertices are indexed from 11 to nn. The input graph is simple, so it contains no loop and no repeated edge.

Output

Print 11 on one line if the input graph is strongly matchable, and 1-1 otherwise. The output is a single integer.