Problem p00539 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <utility>
#include <vector>
#define INF 1e11;
using namespace std;
typedef long long ll;
struct edge {
  ll to, cost;
};
typedef pair<ll, ll> pii;
ll solve();
void dijkstra(ll a);
void binary(ll a, ll b);
vector<edge> vec[100010];
ll D[100100];
vector<ll> road;
ll Cost[100100] = {0};
ll ANS = INF;

int N, M, C;

int main() {
  scanf("%d%d%d", &N, &M, &C);
  for (int i = 0; i < M; i++) {
    int A, B, L;
    scanf("%d%d%d", &A, &B, &L);
    edge test1, test2;
    test1.to = B;
    test1.cost = L;
    test2.to = A;
    test2.cost = L;
    vec[A].push_back(test1);
    vec[B].push_back(test2);
  }
  printf("%lld\\n", solve());
  return 0;
}

ll solve() {
  dijkstra(1);
  for (int i = 0; i < N; i++) {
    road.push_back(D[i + 1]);
  }
  sort(road.begin(), road.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < vec[i + 1].size(); j++) {
      if (D[vec[i + 1][j].to] > D[i + 1] ||
          (D[vec[i + 1][j].to] == D[i + 1] && i + 1 < vec[i + 1][j].to)) {
        binary(D[vec[i + 1][j].to], vec[i + 1][j].cost);
      }
    }
  }
  for (int i = N - 2; i >= 0; i--) {
    Cost[i] += Cost[i + 1];
  }
  for (int i = 0; i < N; i++) {
    ANS = min(ANS, Cost[i] + road[i] * C);
  }
  return ANS;
}

void binary(ll a, ll b) {
  int l = 0;
  int r = N;
  while (r - l > 0) {
    int m = (l + r) / 2;
    if (road[m] == a) {
      Cost[m - 1] += b;
      break;
    }
    if (a > road[m])
      l = m + 1;
    else
      r = m;
  }
  return;
}

void dijkstra(ll a) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  for (int i = 0; i < N; i++) {
    D[i + 1] = INF;
  }
  D[1] = 0;
  que.push(pii(0, 1));
  while (que.size()) {
    pii test = que.top();
    que.pop();
    ll now = test.second;
    if (D[now] > test.first)
      continue;
    for (int i = 0; i < vec[now].size(); i++) {
      edge E = vec[now][i];
      if (D[E.to] > D[now] + E.cost) {
        D[E.to] = D[now] + E.cost;
        que.push(pii(D[E.to], E.to));
      }
    }
  }
  return;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <utility>
#include <vector>
#define INF 1e11;
using namespace std;
typedef long long ll;
struct edge {
  ll to, cost;
};
typedef pair<ll, ll> pii;
ll solve();
void dijkstra(ll a);
void binary(ll a, ll b);
vector<edge> vec[100010];
ll D[10010];
vector<ll> road;
ll Cost[10010] = {0};
ll ANS = INF;

int N, M, C;

int main() {
  scanf("%d%d%d", &N, &M, &C);
  for (int i = 0; i < M; i++) {
    int A, B, L;
    scanf("%d%d%d", &A, &B, &L);
    edge test1, test2;
    test1.to = B;
    test1.cost = L;
    test2.to = A;
    test2.cost = L;
    vec[A].push_back(test1);
    vec[B].push_back(test2);
  }
  printf("%lld\\n", solve());
  return 0;
}

ll solve() {
  dijkstra(1);
  for (int i = 0; i < N; i++) {
    road.push_back(D[i + 1]);
  }
  sort(road.begin(), road.end());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < vec[i + 1].size(); j++) {
      if (D[vec[i + 1][j].to] > D[i + 1] ||
          (D[vec[i + 1][j].to] == D[i + 1] && i + 1 < vec[i + 1][j].to)) {
        binary(D[vec[i + 1][j].to], vec[i + 1][j].cost);
      }
    }
  }
  for (int i = N - 2; i >= 0; i--) {
    Cost[i] += Cost[i + 1];
  }
  for (int i = 0; i < N; i++) {
    ANS = min(ANS, Cost[i] + road[i] * C);
  }
  return ANS;
}

void binary(ll a, ll b) {
  int l = 0;
  int r = N;
  while (r - l > 0) {
    int m = (l + r) / 2;
    if (road[m] == a) {
      Cost[m - 1] += b;
      break;
    }
    if (a > road[m])
      l = m + 1;
    else
      r = m;
  }
  return;
}

void dijkstra(ll a) {
  priority_queue<pii, vector<pii>, greater<pii>> que;
  for (int i = 0; i < N; i++) {
    D[i + 1] = INF;
  }
  D[1] = 0;
  que.push(pii(0, 1));
  while (que.size()) {
    pii test = que.top();
    que.pop();
    ll now = test.second;
    if (D[now] > test.first)
      continue;
    for (int i = 0; i < vec[now].size(); i++) {
      edge E = vec[now][i];
      if (D[E.to] > D[now] + E.cost) {
        D[E.to] = D[now] + E.cost;
        que.push(pii(D[E.to], E.to));
      }
    }
  }
  return;
}