Problem p03560 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <deque>
#include <functional>
#include <utility>

template <typename Key, typename T, class Compare = std::greater<Key>>
class _01Heap {
public:
  using key_type = Key;
  using mapped_type = T;
  using value_type = std::pair<key_type, mapped_type>;
  using reference = value_type &;
  using const_reference = const value_type &;
  using key_compare = Compare;
  using container_type = std::deque<value_type>;
  using size_type = typename container_type::size_type;
  class value_compare {
    friend class _01Heap;
    const key_compare comp;
    value_compare() : comp() {}

  public:
    constexpr bool operator()(const_reference x, const_reference y) const {
      return comp(x.first, y.first);
    }
  };

private:
  const value_compare comp;
  container_type dq;
  size_type size_;

public:
  _01Heap() : comp(), dq(), size_(0) {}
  const_reference top() const {
    assert(size_);
    return dq.front();
  }
  void pop() {
    assert(size_);
    --size_;
    dq.pop_front();
  }
  void push(const_reference x) {
    if (!size_)
      dq.push_front(x);
    else {
      assert(!comp(dq.front(), x));
      if (comp(x, dq.front())) {
        assert(!comp(dq.back(), x));
        dq.push_back(x);
      } else
        dq.push_front(x);
    }
    ++size_;
  }
  size_type size() const noexcept { return size_; }
  bool empty() const noexcept { return !size_; }
};

struct edge {
  int to;
  int cost;
};
#include <iostream>
#include <limits>
#include <tuple>
#include <vector>
int main(void) {
  int k;
  std::cin >> k;
  std::vector<std::vector<edge>> G(k);
  for (int i = 0; i < k; ++i) {
    G[i].push_back({i * 10 % k, 0});
    G[i].push_back({(i + 1) % k, 1});
  }
  _01Heap<int, int> Q;
  static constexpr int INF = std::numeric_limits<int>::max();
  std::vector<int> d(k, INF);
  Q.push({1, 1});
  d[1] = 1;
  int v, c;
  while (!Q.empty()) {
    std::tie(c, v) = Q.top();
    Q.pop();
    if (d[v] < c)
      continue;
    for (const auto &e : G[v]) {
      if (c + e.cost < d[e.to]) {
        d[e.to] = c + e.cost;
        Q.push({d[e.to], e.to});
      }
    }
  }
  std::cout << d[0] << std::endl;
  return 0;
}

Fixed submission:
#include <cassert>
#include <deque>
#include <functional>
#include <utility>

template <typename Key, typename T, class Compare = std::greater<Key>>
class _01Heap {
public:
  using key_type = Key;
  using mapped_type = T;
  using value_type = std::pair<key_type, mapped_type>;
  using reference = value_type &;
  using const_reference = const value_type &;
  using key_compare = Compare;
  using container_type = std::deque<value_type>;
  using size_type = typename container_type::size_type;
  class value_compare {
    friend class _01Heap;
    const key_compare comp;
    value_compare() : comp() {}

  public:
    constexpr bool operator()(const_reference x, const_reference y) const {
      return comp(x.first, y.first);
    }
  };

private:
  const value_compare comp;
  container_type dq;
  size_type size_;

public:
  _01Heap() : comp(), dq(), size_(0) {}
  const_reference top() const {
    assert(size_);
    return dq.front();
  }
  void pop() {
    assert(size_);
    --size_;
    dq.pop_front();
  }
  void push(const_reference x) {
    if (!size_)
      dq.push_front(x);
    else {
      // assert(!comp(dq.front(), x));
      if (comp(x, dq.front())) {
        assert(!comp(dq.back(), x));
        dq.push_back(x);
      } else
        dq.push_front(x);
    }
    ++size_;
  }
  size_type size() const noexcept { return size_; }
  bool empty() const noexcept { return !size_; }
};

struct edge {
  int to;
  int cost;
};
#include <iostream>
#include <limits>
#include <tuple>
#include <vector>
int main(void) {
  int k;
  std::cin >> k;
  std::vector<std::vector<edge>> G(k);
  for (int i = 0; i < k; ++i) {
    G[i].push_back({i * 10 % k, 0});
    G[i].push_back({(i + 1) % k, 1});
  }
  _01Heap<int, int> Q;
  static constexpr int INF = std::numeric_limits<int>::max();
  std::vector<int> d(k, INF);
  Q.push({1, 1});
  d[1] = 1;
  int v, c;
  while (!Q.empty()) {
    std::tie(c, v) = Q.top();
    Q.pop();
    if (d[v] < c)
      continue;
    for (const auto &e : G[v]) {
      if (c + e.cost < d[e.to]) {
        d[e.to] = c + e.cost;
        Q.push({d[e.to], e.to});
      }
    }
  }
  std::cout << d[0] << std::endl;
  return 0;
}