Problem:
Consider placing N flags on a line. Flags are numbered through 1 to N.  Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.  Decide whether it is possible to place all N flags. If it is possible, print such a configulation.

Incorrect submission (verdict: Wrong Answer):
from itertools import product
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 6 + 100)


class StronglyConnectedComponets:
    def __init__(self, n: int) -> None:
        self.n = n
        self.edges = [[] for _ in range(n)]
        self.rev_edeges = [[] for _ in range(n)]
        self.vs = []
        self.order = [0] * n
        self.used = [False] * n

    def add_edge(self, from_v: int, to_v: int) -> None:
        self.edges[from_v].append(to_v)
        self.rev_edeges[to_v].append(from_v)

    def dfs(self, v: int) -> None:
        self.used[v] = True
        for child in self.edges[v]:
            if not self.used[child]:
                self.dfs(child)
        self.vs.append(v)

    def rdfs(self, v: int, k: int) -> None:
        self.used[v] = True
        self.order[v] = k
        for child in self.rev_edeges[v]:
            if not self.used[child]:
                self.rdfs(child, k)

    def run(self) -> int:
        self.used = [False] * self.n
        self.vs.clear()
        for v in range(self.n):
            if not self.used[v]:
                self.dfs(v)
        self.used = [False] * self.n
        k = 0
        for v in reversed(self.vs):
            if not self.used[v]:
                self.rdfs(v, k)
                k += 1
        return k


class TwoSat(StronglyConnectedComponets):
    def __init__(self, num_var: int) -> None:
        super().__init__(2 * num_var + 1)
        self.num_var = num_var
        self.ans = []

    def add_constraint(self, a: int, b: int) -> None:
        super().add_edge(self._neg(a), self._pos(b))
        super().add_edge(self._neg(b), self._pos(a))

    def _pos(self, v: int) -> int:
        return v if v > 0 else self.num_var - v

    def _neg(self, v: int) -> int:
        return self.num_var + v if v > 0 else -v

    def run(self) -> bool:
        super().run()
        self.ans.clear()
        for i in range(self.num_var):
            if self.order[i + 1] == self.order[i + self.num_var + 1]:
                return False
            self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1])
        return True


def main() -> None:
    N, D = map(int, input().split())

    flags = []
    for _ in range(N):
        x_i, y_i = map(int, input().split())
        if abs(x_i - y_i) < D:
            print("No")
            break
        flags.append((x_i, y_i))

    sat = TwoSat(2 * N)
    
    
    for i in range(N):
        sat.add_constraint(2*i+1, 2*i+2)

    
    
    for i, (x_i, y_i) in enumerate(flags):
        for j, (x_j, y_j) in enumerate(flags[i+1:], i+1):
            if abs(x_i - x_j) < D:
                sat.add_constraint(-(2*i+1), -(2*j+1))
            if abs(y_i - x_j) < D:
                sat.add_constraint(-(2*i+2), -(2*j+1))
            if abs(x_i - y_j) < D:
                sat.add_constraint(-(2*i+1), -(2*j+2))
            if abs(y_i - y_j) < D:
                sat.add_constraint(-(2*i+2), -(2*j+2))
    if sat.run():
        print("Yes")
        print(*[x_i if sat.ans[2*i-1] else y_i for i, (x_i, y_i) in enumerate(flags)], sep="\n")
    else:
        print("No")


if __name__ == "__main__":
    main()


Fixed, accepted submission:
import sys

input = sys.stdin.buffer.readline


class StronglyConnectedComponets:
    def __init__(self, n: int) -> None:
        self.n = n
        self.edges = [[] for _ in range(n)]
        self.rev_edeges = [[] for _ in range(n)]
        self.vs = []
        self.order = [0] * n
        self.used = [False] * n

    def add_edge(self, from_v: int, to_v: int) -> None:
        self.edges[from_v].append(to_v)
        self.rev_edeges[to_v].append(from_v)

    def dfs(self, v: int) -> None:
        self.used[v] = True
        for child in self.edges[v]:
            if not self.used[child]:
                self.dfs(child)
        self.vs.append(v)

    def rdfs(self, v: int, k: int) -> None:
        self.used[v] = True
        self.order[v] = k
        for child in self.rev_edeges[v]:
            if not self.used[child]:
                self.rdfs(child, k)

    def run(self) -> int:
        self.used = [False] * self.n
        self.vs.clear()
        for v in range(self.n):
            if not self.used[v]:
                self.dfs(v)
        self.used = [False] * self.n
        k = 0
        for v in reversed(self.vs):
            if not self.used[v]:
                self.rdfs(v, k)
                k += 1
        return k


class TwoSat(StronglyConnectedComponets):
    def __init__(self, num_var: int) -> None:
        super().__init__(2 * num_var + 1)
        self.num_var = num_var
        self.ans = []

    def add_constraint(self, a: int, b: int) -> None:
        super().add_edge(self._neg(a), self._pos(b))
        super().add_edge(self._neg(b), self._pos(a))

    def _pos(self, v: int) -> int:
        return v if v > 0 else self.num_var - v

    def _neg(self, v: int) -> int:
        return self.num_var + v if v > 0 else -v

    def run(self) -> bool:
        super().run()
        self.ans.clear()
        for i in range(self.num_var):
            if self.order[i + 1] == self.order[i + self.num_var + 1]:
                return False
            self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1])
        return True


def main() -> None:
    N, D = map(int, input().split())

    flags = [tuple(int(x) for x in input().split()) for _ in range(N)]

    
    sat = TwoSat(N)

    
    
    for i, (x_i, y_i) in enumerate(flags, 1):
        for j, (x_j, y_j) in enumerate(flags[i:], i+1):
            if abs(x_i - x_j) < D:
                sat.add_constraint(-i, -j)
            if abs(y_i - x_j) < D:
                sat.add_constraint(i, -j)
            if abs(x_i - y_j) < D:
                sat.add_constraint(-i, j)
            if abs(y_i - y_j) < D:
                sat.add_constraint(i, j)
    if sat.run():
        print("Yes")
        print(*[x_i if sat.ans[i] else y_i for i, (x_i, y_i) in enumerate(flags)], sep="\n")
    else:
        print("No")


if __name__ == "__main__":
    main()