Problem p00539 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

#define MAXM 200001
#define MAXN 100001
#define INF 100000000

using namespace std;

typedef long long int int64;

typedef struct {
  vector<int64> dest;
  vector<int64> route;
  int64 cost;
  int64 index;
} node;

typedef struct {
  bool operator()(const node *a, const node *b) // operator<
  {
    return a->cost > b->cost;
  }
} cmp_pnode;

typedef struct {
  int64 dist;
  int64 count; // 0-
  int64 sum;
} dst;

int64 N, M, C, A[MAXM], B[MAXM], D[MAXM];
node S[MAXN];
vector<node *> R;
bool E[MAXN];
priority_queue<node *, vector<node *>, cmp_pnode> prc;

signed main(void) {
  for (int64 i = 0; i < MAXN; i++) {
    S[i].cost = INF;
    S[i].index = i;
    E[i] = false;
  }
  cin >> N >> M >> C;
  for (int64 i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> D[i];
    A[i]--;
    B[i]--;
    S[A[i]].dest.push_back(B[i]);
    S[A[i]].route.push_back(D[i]);
    S[B[i]].dest.push_back(A[i]);
    S[B[i]].route.push_back(D[i]);
  }
  S[0].cost = 0;
  prc.push(&S[0]);
  node *tp;
  while (!prc.empty()) {
    tp = prc.top();
    prc.pop();
    for (int64 i = 0; i < tp->dest.size(); i++) {
      if (S[tp->dest[i]].cost > tp->cost + tp->route[i]) {
        S[tp->dest[i]].cost = tp->cost + tp->route[i];
        prc.push(&S[tp->dest[i]]);
      }
    }
  }
  for (int64 i = 0; i < N; i++) {
    R.push_back(&S[i]);
  }
  sort(R.begin(), R.end(),
       [](const node *a, const node *b) { return a->cost < b->cost; });
  int64 sum = 0;
  for (int64 i = 0; i < M; i++) {
    sum = sum + D[i];
  }
  int64 mincost = sum;
  for (auto itr = R.begin(); itr != R.end(); itr++) {
    E[(*itr)->index] = true;
    for (int64 i = 0; i < (*itr)->dest.size(); i++) {
      if (E[(*itr)->dest[i]]) {
        sum -= (*itr)->route[i];
      }
    }
    mincost = min(mincost, sum + (C * (*itr)->cost));
  }
  cout << mincost << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>

using namespace std;

#define MAX_M 200001
#define MAX_N 100001

uint64_t N, M, C, A[MAX_M], B[MAX_M], D[MAX_M], cost[MAX_N];
bool decd[MAX_N];

int main(void) {
  cin >> N >> M >> C;
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i] >> D[i];
    A[i]--;
    B[i]--;
  }
  for (int i = 1; i < MAX_N; i++) {
    cost[i] = UINT64_MAX;
    decd[i] = false;
  }
  bool loop = true, update;
  uint64_t least_i, least_c;
  while (loop) {
    least_i = 0;
    least_c = UINT64_MAX;
    update = false;
    for (int i = 0; i < N; i++) {
      if (least_c > cost[i] && !decd[i]) {
        least_i = i;
        least_c = cost[i];
        update = true;
      }
    }
    if (update) {
      decd[least_i] = true;
      for (int i = 0; i < M; i++) {
        if (A[i] == least_i && cost[B[i]] >= cost[A[i]] + D[i] && !decd[B[i]]) {
          cost[B[i]] = cost[A[i]] + D[i];
        }
        if (B[i] == least_i && cost[A[i]] >= cost[B[i]] + D[i] && !decd[A[i]]) {
          cost[A[i]] = cost[B[i]] + D[i];
        }
      }
    } else
      break;
  }
  uint64_t least_cost = UINT64_MAX;
  for (int i = 0; i < N; i++) {
    uint64_t cc = (C * cost[i]);
    for (int ii = 0; ii < M + 1; ii++) {
      if (cost[A[ii]] > cost[i] || cost[B[ii]] > cost[i])
        cc += D[ii];
    }
    if (least_cost > cc)
      least_cost = cc;
  }
  cout << least_cost << endl;
  return 0;
}