Choosing mutually exclusive pairs efficiently

前端 未结 4 1918
滥情空心
滥情空心 2021-01-17 19:12

This is a problem that could be done with some type of brute-force algorithm, but I was wondering if there are some efficient ways of doing this.

Let\'s assume that

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-17 20:00

    Your question is equivalent to finding a maximum matching on a graph. The nodes of your graph are integers, and your pairs (a, b) are edges of the graph. A matching is a set of pairwise non-adjacent edges, which is equivalent to saying the same integer doesn't appear in two edges.

    A polynomial time solution to this problem is the Blossom algorithm also known as Edmond's algorithm. It's rather too complicated to include the details in the answer here.

提交回复
热议问题