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

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll, ll> P;

// 1. dp,?????°
int n, m;
ll c;

vector<P> road[100001];
ll d[200001] = {};
ll dp[100001] = {};
ll dp2[100001] = {};

int main() {
  // 2. ??\\???
  cin >> n >> m >> c;

  ll a, b, d1;
  ll totalC = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> d1;
    road[a].push_back(P(b, i));
    road[b].push_back(P(a, i));
    d[i] = d1;
    totalC += d1;
  }

  queue<P> que;

  // 3.?????????
  for (int i = 0; i < 100001; ++i)
    dp[i] = 10000000001;
  que.push(P(1, 0));
  // 4.loop
  //
  while (!que.empty()) {
    // 5.???????????????
    P p1 = que.front();
    que.pop();
    ll pos = p1.first;
    ll cost = p1.second;
    if (dp[pos] < cost)
      continue;
    dp[pos] = cost;
    for (auto it : road[pos]) {
      int pos2 = it.first;
      int roadm = it.second;
      que.push(P(pos2, cost + d[roadm]));
    }
  }
  priority_queue<P, vector<P>, greater<P>> que2;
  ll x = 0;
  ll total = 20000000000;
  for (ll i = 1; i < n + 1; ++i)
    que2.push(P(dp[i], i));
  while (!que2.empty()) {
    // 5.???????????????
    P p2 = que2.top();
    que2.pop();
    ll cos = p2.first;
    ll pos = p2.second;
    dp2[pos] = 1;
    x = cos;
    for (auto it : road[pos]) {
      ll pos2 = it.first;
      ll roadm = it.second;
      if (dp2[pos2] > 0)
        totalC -= d[roadm];
    }
    total = min(total, c * x + totalC);
  }

  // 4.??????
  cout << total << endl;
  return 0;
}

Error: 0

Fixed submission:

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<ll, ll> P;

// 1. dp,?????°
int n, m;
ll c;

vector<P> road[100001];
ll d[100001] = {};
ll dp[100001] = {};
ll dp2[100001] = {};

int main() {
  // 2. ??\\???
  cin >> n >> m >> c;

  ll a, b, d1;
  ll totalC = 0;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> d1;
    road[a].push_back(P(b, i));
    road[b].push_back(P(a, i));
    d[i] = d1;
    totalC += d1;
  }

  queue<P> que;

  // 3.?????????
  for (int i = 0; i < 100001; ++i)
    dp[i] = 10000000001;
  que.push(P(1, 0));
  // 4.loop
  //
  while (!que.empty()) {
    // 5.???????????????
    P p1 = que.front();
    que.pop();
    ll pos = p1.first;
    ll cost = p1.second;
    if (dp[pos] < cost)
      continue;
    dp[pos] = cost;
    for (auto it : road[pos]) {
      int pos2 = it.first;
      int roadm = it.second;
      que.push(P(pos2, cost + d[roadm]));
    }
  }
  priority_queue<P, vector<P>, greater<P>> que2;
  ll x = 0;
  ll total = 20000000000;
  for (ll i = 1; i < n + 1; ++i)
    que2.push(P(dp[i], i));
  while (!que2.empty()) {
    // 5.???????????????
    P p2 = que2.top();
    que2.pop();
    ll cos = p2.first;
    ll pos = p2.second;
    dp2[pos] = 1;
    x = cos;
    for (auto it : road[pos]) {
      ll pos2 = it.first;
      ll roadm = it.second;
      if (dp2[pos2] > 0)
        totalC -= d[roadm];
    }
    total = min(total, c * x + totalC);
  }

  // 4.??????
  cout << total << endl;
  return 0;
}