## Exercise ‹11›:

3-COLORABILITY $\leq$ SAT
Reduce the 3-COLORABILITY problem to the SAT problem. These problems are defined as follows:
• 3-COLORABILITY: given an undirected graph $G$, is $G$ $3$-colorable? In other words, is there a mapping $M$ from the nodes of $G$ to $\{1,2,3\}$ satisfying $M(u)\neq M(v)$ for each edge $\{u,v\}$ of $G$?
More formally, this problem can be defined as the following set:
$\{ G=\langle V,E\rangle \mid \exists M:V\to\{1,2,3\}\text{ total}: \forall \{u,v\}\in E: M(u)\neq M(v) \}$
• SAT: given a boolean formula $F$ in conjunctive normal form, is $F$ satisfiable?
More formally, this problem can be defined as the following set:
$\{ F=C_1\wedge\ldots\wedge C_n \mid F\text{ satisfiable} \}$
The input and output of the reduction conform to the following data types:
• in: struct {
numnodes: int
edges: array of array [2] of int
adjacents: array of array of int
adjacencymatrix: array of array of int
}

The input is an undirected graph. The graph is given by means of four different kinds of information: the number of nodes in.numnodes, the list of edges in.edges, for each node the list of its adjacent nodes in.adjacents, and the adjacency matrix in.adjacencymatrix. The nodes are integers between $1$ and in.numnodes, and thus, the $0$’th position of in.adjacents does not contain useful data and should be ignored; for any other position $p$, in.adjacents[p] is the list of nodes adjacent to $p$. For the same reason, the $0$’th row and column of in.adjacencymatrix do not contain useful data and should be ignored; for any other row $r$ and column $c$, in.adjacencymatrix[r][c] is $0$ when there is no edge between the nodes $r$ and $c$, and $1$ otherwise.

Note: The input graph has at least $4$ nodes, no repeated edges, nor self-loop edges.
• out: array of array of string

The output is a list of clauses. A positive literal is represented by a positive number or by a string not starting with «-», a negated literal by a negative number or a string starting with «-».

Note: If the output is an empty formula, it is considered satisfiable. If the formula has any empty clause, it is considered unsatisfiable.
Authors: Carles Creus / Documentation:
 main { // Write your reduction here... } To be able to submit you need to either log in, register, or become a guest.