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

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define int ll
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
signed main() {
  int V, e, s;
  cin >> V >> e >> s;
  vector<vector<pii>> edge(V, vector<pii>());
  rep(i, e) {
    pii a;
    int c;
    cin >> a.first >> a.second >> c;
    edge[a.first].push_back(pii(a.second, c));
  }
  vector<int> d(V, INF);
  d[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> que;
  que.push(pii(d[s], s));
  while (!que.empty()) {
    pii now = que.top();
    que.pop();
    if (d[now.second] < now.first)
      continue;
    for (int i = 0; i < edge[now.second].size(); i++) {
      pii next = edge[now.second][i];
      if (now.first + next.second > d[next.first])
        continue;
      d[next.first] = now.first + next.second;
      que.push(pii(d[next.first], next.first));
    }
  }
  for (int v = 0; v < V; v++)
    if (d[v] == INF)
      cout << "INF" << endl;
    else
      cout << d[v] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
  if (a > b)
    a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
  if (a < b)
    a = b;
}
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
int main() {
  int V, e, s;
  cin >> V >> e >> s;
  vector<vector<pii>> edge(V, vector<pii>());
  rep(i, e) {
    pii a;
    int c;
    cin >> a.first >> a.second >> c;
    edge[a.first].push_back(pii(a.second, c));
  }
  for (int v = 0; v < V; v++) {
    vector<int> d(V, INF);
    d[s] = 0;
    if (v == s) {
      cout << 0 << endl;
      continue;
    }
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.push(pii(d[s], s));
    while (!que.empty()) {
      pii now = que.top();
      que.pop();
      if (now.second == v)
        break;
      if (d[now.second] < now.first)
        continue;
      for (int i = 0; i < edge[now.second].size(); i++) {
        pii next = edge[now.second][i];
        if (now.first + next.second > d[next.first])
          continue;
        d[next.first] = now.first + next.second;
        que.push(pii(d[next.first], next.first));
      }
    }
    if (d[v] == INF)
      cout << "INF" << endl;
    else
      cout << d[v] << endl;
  }
}