macro_rules! read_line_to_tuple {
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

struct Scc {
    n: usize,
    graph: Vec<Vec<usize>>,
    rev_graph: Vec<Vec<usize>>,
    post_order: Vec<usize>,
    component: Vec<usize>,
}

impl Scc {
    fn new(n: usize) -> Scc {
        Scc {
            n,
            graph: vec![Vec::new(); n],
            rev_graph: vec![Vec::new(); n],
            component: vec![n; n],
            post_order: Vec::with_capacity(n),
        }
    }

    fn add_edge(&mut self, from: usize, to: usize) {
        self.graph[from].push(to);
        self.rev_graph[to].push(from);
    }

    fn dfs(&mut self, from: usize) {
        self.component[from] = self.n + 1;
        for to in self.graph[from].clone() {
            if self.component[to] == self.n {
                self.dfs(to);
            }
        }
        self.post_order.push(from);
    }
    
    fn rev_dfs(&mut self, from: usize, k: usize) {
        self.component[from] = k;
        for to in self.rev_graph[from].clone() {
            if self.component[to] > self.n {
                self.rev_dfs(to, k);
            }
        }
    }

    fn solve(&mut self) {
        for i in 0..self.n {
            if self.component[i] == self.n {
                self.dfs(i);
            }
        }

        let mut k: usize = 0;
        for i in (0..self.n).rev() {
            if self.component[self.post_order[i]] > self.n {
                self.rev_dfs(self.post_order[i], k);
                k += 1;
            }
        }
    }
}

struct TwoSat {
    n: usize,
    scc: Scc,
}

impl TwoSat {
    fn new(n: usize) -> TwoSat {
        TwoSat {
            n,
            scc: Scc::new(n * 2),
        }
    }

    fn add_closure(&mut self, x: usize, y: usize) {
        self.scc.add_edge((x + self.n) % (self.n * 2), y);
        self.scc.add_edge((y + self.n) % (self.n * 2), x);
    }

    fn solve(&mut self) -> Option<Vec<bool>> {
        self.scc.solve();

        let mut res = vec![false; self.n];
        for i in 0..self.n {
            if self.scc.component[i] == self.scc.component[i + self.n] {
                return None;
            }
            res[i] = self.scc.component[i] > self.scc.component[i + self.n];
        }

        Some(res)
    }
}

fn main() {
    let (n, d) = read_line_to_tuple!(usize, i64);

    let mut ts = TwoSat::new(n);
    let (mut x, mut y) = (vec![0; n], vec![0; n]);
    for i in 0..n {
        let (a, b) = read_line_to_tuple!(i64, i64);
        x[i] = a;
        y[i] = b;
    }

    for i in 0..n {
        for j in (i + 1)..n {
            if (x[i] - x[j]).abs() < d {
                ts.add_closure(i + n, j + n);
            }
            if (x[i] - y[j]).abs() < d {
                ts.add_closure(i + n, j);
            }
            if (y[i] - x[j]).abs() < d {
                ts.add_closure(i, j + n);
            }
            if (y[i] - y[j]).abs() < d {
                ts.add_closure(i, j);
            }
        }
    }

    let res = ts.solve();
    if let Some(res) = res {
        let mut ans = Vec::with_capacity(n + 1);
        ans.push("Yes".to_string());
        for i in 0..n {
            if res[i] {
                ans.push(x[i].to_string());
            } else {
                ans.push(y[i].to_string());
            }
        }
        println!("{}", ans.join("\n"));
    } else {
        println!("No");
    }
}

Measured memory_bytes: 2412