2

A lot of times, I’ve needed to split a given set of people into a given number of teams but with some complications, like:

  • Alice and Bob CANNOT be on the same team.
  • Carol and David just HAVE TO BE on the same team.

I feel like this is already a thing. There's gotta already be work in this problem. Where would I even start, in terms of an algorithm? It definitely can't be brute-forced.

fernozzle
  • 123
  • 3

1 Answers1

4

Denote each person as a single vertex and connect them by an edge if they are not allowed to be in the same team. If several people have to be on the same team, use a single vertex to represent all of them. Then color the resulting graph by $k$ colors, where $k$ is the number of teams.This problem is the graph coloring problem. To complicate things you may require color certain vertices in the same color. Please follow this for other types of colorings.

D.W.
  • 159,275
  • 20
  • 227
  • 470
fade2black
  • 9,827
  • 2
  • 24
  • 36