Given an undirected graph with 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 pairs such that all vertices belong to some pair, and that both vertices of every pair are directly connected.
Input consists of several cases. Each case begins with and the number of edges , followed by pairs of vertices. Assume , that is even, that vertices are numbered from 1 to , that there are no repeated edges nor edges connecting a vertex to itself, and that there is no isolated vertex.
For every case, tell if the given graph has a maximum matching.
There are polynomial-time algorithms, more or less complicated, to solve this problem. Here, we settle for a simple backtracking.
Input
2 1 1 2 4 4 1 2 3 1 4 1 2 3 4 3 1 2 1 3 1 4 6 8 1 2 1 4 2 3 2 5 2 6 3 4 4 5 4 6
Output
yes yes no no