Given a directed graph $G(V,E)$, vertexes $v, w$ and a list of pairs of vertexes $P$: $$ P = (v_1, w_1), (v_2, w_2), \ldots, (v_k, w_k) $$ The problem is to find a path between $v$ and $w$ which contains no more than one of vertices from each pair. Prove that this problem is NP-complete or give a polynomial algorithm.
I have an idea of using dfs with a disjoint set union (DSU) to solve this problem: first we unite vertexes from each pair, other vertexes unite in a one vertex set. Then we can colour each set in a unique colour. After that we have to find a path between $v$ and $w$ which does not contain two vertexes in one colour. This path can be found with dfs. This algorithm is a polynomial. But I'm still not sure whether this algorithm is correct. Can anyone help?
This problem is NP-complete, which can be proved by a reduction from the problem $3$-SAT.
Let the input of a $3$-SAT instance be
$n$ boolean variables, namely, $x_1$, $x_2$, $\cdots$, $x_n$
$m$ clauses of the form $l_1 \lor l_2 \lor l_3$, where each literal $l_i$ is either $x_j$ or $\neg x_j$ for some $1 \leq j \leq n$
We construct an instance of your problem from the $3$-SAT instance such that there exists a path in your problem if and only if the $3$-SAT instance is satisfiable.
Proof: Obviously, your problem is in the class NP. We prove below that there exists a path from $v$ to $w$ in the graph $G$ constructed without violating the constraints if and only if the $3$-SAT instance is satisfiable.
$\Leftarrow$ Part: If $3$-SAT is satisfiable, for each $c_j = l_{j,1} \lor l_{j,2} \lor l_{j,3}$, at least one of $l_{j,1}$, $l_{j,2}$ and $l_{j,3}$ is evaluated as true. Without loss of generality, suppose $l_{j,1}$ is the one that is true and let the vertex representing $l_{j,1}$ be $u_{j,1}$. We can see that the path $$ \mathcal{P} = v \rightarrow u_{1,1} \rightarrow u_1 \rightarrow u_{2,1} \rightarrow u_2 \rightarrow \cdots \rightarrow u_{m,1} \rightarrow u_m \rightarrow w $$ does not violate any constraint pair.
$\Rightarrow$ Part: Suppose we have a path $\mathcal{P}$ from $v$ to $w$ in $G$ without violating any constraint pair. Then one of $3$ vertices for each clause $c_j$ is visited. Without loss of generality, let the vertex be $u_{j,1}$ and its corresponding literal is $l_{j,1}$. If $l_{j,1} = x_i$, we then set $x_i$ as true; otherwise if $l_{j,1} = \neg x_i$, we set $x_i$ as false. The resulting truth assignment to $x_i$s satisfies the $3$-SAT.