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

#include "bits/stdc++.h"

using namespace std;

#define cerr                                                                   \\
  if (false)                                                                   \\
  cerr
#define what(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
const ll INF = 1e18;
const ll lim = 3000;
int costo[60][60];
int tiempo[60][60];
int cambio[60][2];

bool vis2[60][3000];
set<pair<int, int>> vis;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  ll n, m, s;
  cin >> n >> m >> s;

  vector<vector<int>> graph(n);

  int a, b, c, d;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c >> d;
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
    costo[a][b] = costo[b][a] = c;
    tiempo[a][b] = tiempo[b][a] = d;
  }

  for (int i = 0; i < n; i++) {
    cin >> cambio[i][0] >> cambio[i][1];
  }

  priority_queue<iii, vector<iii>, greater<iii>> pq;
  pq.push({0, {min(s, lim), 0}});

  vector<ll> dist(n, INF);
  while (!pq.empty()) {
    ll curr_time = pq.top().first;
    ll curr_money = pq.top().second.first;
    ll curr_index = pq.top().second.second;
    pq.pop();

    if (vis2[curr_index][curr_money])
      continue;
    vis2[curr_index][curr_money] = true;

    dist[curr_index] = min(curr_time, dist[curr_index]);

    // Visitarte a ti mismo
    if (curr_money < 3000) {
      pq.push({curr_time + cambio[curr_index][1],
               {min(curr_money + cambio[curr_index][0], lim), curr_index}});
    }

    for (auto &it : graph[curr_index]) {
      if (costo[curr_index][it] <= curr_money) {
        pq.push({curr_time + tiempo[curr_index][it],
                 {curr_money - costo[curr_index][it], it}});
      }
    }
  }

  for (int i = 1; i < n; i++) {
    cout << dist[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

#define cerr                                                                   \\
  if (false)                                                                   \\
  cerr
#define what(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
const ll INF = 1e18;

int costo[60][60];
int tiempo[60][60];
int cambio[60][2];

bool vis2[60][2501];
set<pair<int, int>> vis;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n, m, s;
  cin >> n >> m >> s;

  vector<vector<int>> graph(n);

  int a, b, c, d;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c >> d;
    --a;
    --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
    costo[a][b] = costo[b][a] = c;
    tiempo[a][b] = tiempo[b][a] = d;
  }

  for (int i = 0; i < n; i++) {
    cin >> cambio[i][0] >> cambio[i][1];
  }

  priority_queue<iii, vector<iii>, greater<iii>> pq;
  pq.push({0, {s, 0}});

  vector<ll> dist(n, INF);
  while (!pq.empty()) {
    ll curr_time = pq.top().first;
    ll curr_money = pq.top().second.first;
    ll curr_index = pq.top().second.second;
    pq.pop();

    if (curr_money > 2500) {
      auto it2 = vis.find({curr_index, curr_money});
      if (it2 != vis.end())
        continue;
      vis.insert({curr_index, curr_money});
    } else {
      if (vis2[curr_index][curr_money])
        continue;
      vis2[curr_index][curr_money] = true;
    }

    dist[curr_index] = min(curr_time, dist[curr_index]);

    // Visitarte a ti mismo
    if (curr_money < 2500) {
      pq.push({curr_time + cambio[curr_index][1],
               {curr_money + cambio[curr_index][0], curr_index}});
    }

    for (auto &it : graph[curr_index]) {
      if (costo[curr_index][it] <= curr_money) {
        pq.push({curr_time + tiempo[curr_index][it],
                 {curr_money - costo[curr_index][it], it}});
      }
    }
  }

  for (int i = 1; i < n; i++) {
    cout << dist[i] << endl;
  }

  return 0;
}