Problem p03044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<bool> f(n, false);
  std::vector<int64_t> l(n, 0);
  std::vector<std::map<int64_t, int64_t>> no(n);

  for (int64_t i = 0; i < n; i++) {
    int64_t u, v, w;
    std::cin >> u >> v >> w;
    u--;
    v--;
    no[u].insert({v, w});
    no[v].insert({u, w});
  }

  f[0] = true;
  l[0] = 0;

  std::set<std::pair<int64_t, int64_t>> q;
  for (const auto &i : no[0]) {
    if (!f[i.first]) {
      q.insert({l[0] + i.second, i.first});
    }
  }

  while (!q.empty()) {
    const auto cost = q.cbegin()->first;
    const auto node = q.cbegin()->second;
    if (!f[node]) {
      f[node] = true;
      l[node] = cost;

      for (const auto &i : no[node]) {
        if (!f[i.first]) {
          q.insert({cost + i.second, i.first});
        }
      }
    }
    q.erase(q.begin());
  }

  for (const auto i : l) {
    if (i % 2 == 0) {
      std::cout << 0 << std::endl;
    } else {
      std::cout << 1 << std::endl;
    }
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<bool> f(n, false);
  std::vector<int64_t> l(n, 0);
  std::vector<std::map<int64_t, int64_t>> no(n);

  for (int64_t i = 0; i < n - 1; i++) {
    int64_t u, v, w;
    std::cin >> u >> v >> w;
    u--;
    v--;
    no[u].insert({v, w});
    no[v].insert({u, w});
  }

  f[0] = true;
  l[0] = 0;

  std::set<std::pair<int64_t, int64_t>> q;
  for (const auto &i : no[0]) {
    if (!f[i.first]) {
      q.insert({l[0] + i.second, i.first});
    }
  }

  while (!q.empty()) {
    const auto cost = q.cbegin()->first;
    const auto node = q.cbegin()->second;
    if (!f[node]) {
      f[node] = true;
      l[node] = cost;

      for (const auto &i : no[node]) {
        if (!f[i.first]) {
          q.insert({cost + i.second, i.first});
        }
      }
    }
    q.erase(q.begin());
  }

  for (const auto i : l) {
    if (i % 2 == 0) {
      std::cout << 0 << std::endl;
    } else {
      std::cout << 1 << std::endl;
    }
  }

  return 0;
}