Maximum matching

Given an undirected graph with nn vertices, a matching is a subset of the edges with no common vertices. Write a program to tell if a given graph has a maximum matching, that is, a grouping of the vertices in n/2n/2 pairs such that all vertices belong to some pair, and that both vertices of every pair are directly connected.

Input

Input consists of several cases. Each case begins with nn and the number of edges mm, followed by mm pairs of vertices. Assume 2n202 \le n \le 20, that nn is even, that vertices are numbered from 1 to nn, that there are no repeated edges nor edges connecting a vertex to itself, and that there is no isolated vertex.

Output

For every case, tell if the given graph has a maximum matching.

Observation

There are polynomial-time algorithms, more or less complicated, to solve this problem. Here, we settle for a simple backtracking.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:34:36.554Z

© Jutge.org, 2006–2026.
https://jutge.org