alexjercan/bugnet huggingface dataset:
Problem p02358 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n;
  cin >> n;
  vvi in(n, vi(4));
  rep(i, n) rep(j, 4) cin >> in[i][j];
  vi x, y;
  rep(i, n) rep(j, 4) if (j % 2) y.pb(in[i][j]);
  else x.pb(in[i][j]);
  sort(all(x));
  sort(all(y));
  x.erase(unique(all(x)), x.end());
  y.erase(unique(all(y)), y.end());

  vvi tmp = in;
  rep(i, n) rep(j, 4) if (j % 2) tmp[i][j] =
      find(all(y), tmp[i][j]) - y.begin();
  else tmp[i][j] = find(all(x), tmp[i][j]) - x.begin();
  vvi field(x.size(), vi(y.size()));
  rep(i, n) loop(j, tmp[i][0], tmp[i][2]) loop(k, tmp[i][1], tmp[i][3])
      field[j][k] = true;
  ll out = 0;
  rep(i, x.size()) rep(j, y.size()) if (field[i][j]) out +=
      (ll)(x[i + 1] - x[i]) * (y[j + 1] - y[j]);
  cout << out << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n;
  cin >> n;
  vvi in(n, vi(4));
  rep(i, n) rep(j, 4) cin >> in[i][j];
  vi x, y;
  rep(i, n) rep(j, 4) loop(k, -1, 2) if (j % 2) y.pb(in[i][j] + k);
  else x.pb(in[i][j] + k);
  sort(all(x));
  sort(all(y));
  x.erase(unique(all(x)), x.end());
  y.erase(unique(all(y)), y.end());

  vvi tmp = in;
  rep(i, n) rep(j, 4) if (j % 2) tmp[i][j] =
      find(all(y), tmp[i][j]) - y.begin();
  else tmp[i][j] = find(all(x), tmp[i][j]) - x.begin();
  vvi field(x.size(), vi(y.size()));
  rep(i, n) loop(j, tmp[i][0], tmp[i][2]) loop(k, tmp[i][1], tmp[i][3])
      field[j][k] = true;
  ll out = 0;
  rep(i, x.size()) rep(j, y.size()) if (field[i][j]) out +=
      (ll)(x[i + 1] - x[i]) * (y[j + 1] - y[j]);
  cout << out << endl;
}
Problem p02359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int a[100010];

int main() {
  int N, T, e, q, maxn = 0;
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> e >> q;
    a[e]++;
    a[q]--;
  }
  for (int i = 1; i <= T + 1; i++) {
    a[i] += a[i - 1];
    maxn = max(maxn, a[i - 1]);
  }
  cout << maxn << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int a[100010];

int main() {
  int N, T, e, q, maxn = 0;
  cin >> N >> T;
  for (int i = 0; i < N; i++) {
    cin >> e >> q;
    for (int j = e; j < q; j++) {
      a[j]++;
    }
  }
  for (int i = 0; i <= T; i++) {
    maxn = max(maxn, a[i]);
  }
  cout << maxn << endl;
  return 0;
}
Problem p02359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

void solve() {
  int n, t;
  cin >> n >> t;
  vector<int> imos(t + 1);
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    imos[l]++;
    imos[r]--;
  }
  for (int i = 1; i <= t; i++) {
    imos[i] += imos[i - 1];
  }
  cout << *max_element(imos.begin(), imos.end()) << endl;
}
int main(void) {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define N 100000

int main() {
  int n, t, l[N], r[N];
  unordered_map<int, int> mp;
  cin >> n >> t;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int k = l[i]; r[i] > k; ++k) {
      if (mp.count(k) == 0) {
        mp[k] = 1;
      } else {
        ++mp[k];
      }
    }
  }
  int max = 0;
  for (auto elm : mp) {
    if (max < elm.second) {
      max = elm.second;
    }
  }
  cout << max << endl;

  return 0;
}
Problem p02359 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int Time[100200];
int T, N;
int x, y;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> N >> T;

  for (int i = 0; i < N; i++) {
    cin >> x >> y;
    Time[x + 1]++;
    Time[y + 1]--;
  }

  for (int i = 1; i < T + 4; i++) {
    Time[i] = Time[i - 1] + Time[i];
  }

  int MAX = 0;

  for (int i = 1; i < T + 4; i++) {
    MAX = max(MAX, Time[i]);
  }

  cout << MAX << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

typedef struct {
  int ini, fin;
} _ura;

int n, t;
_ura rangos[10005];
int total[10005];

bool comparador(_ura a, _ura b) {
  if (a.ini < b.ini)
    return true;
  return a.fin < b.fin;
}

int maximo;

void recorrer() {
  for (int i = 0; i < n; i++) {
    total[rangos[i].ini]++;
    total[rangos[i].fin]--;
  }
  int temp = 0;
  for (int i = 0; i <= t; i++) {
    temp += total[i];
    if (maximo < temp)
      maximo = temp;
  }
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> rangos[i].ini >> rangos[i].fin;
  }
  recorrer();
  cout << maximo << endl;
  return 0;
}
Problem p02359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {

  int N, T;
  cin >> N >> T;

  int a[100001] = {};
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;

    a[l]++;
    a[r]--;
  }

  for (int i = 1; i < T; i++) {
    a[i] += a[i - 1];
  }

  int ans = 0;
  for (int i = 0; i < T; i++) {
    ans = max(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  int N, T;
  cin >> N >> T;

  int a[100000] = {};
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;

    for (int j = l; j < r; j++) {
      a[j]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < 100000; i++) {
    if (a[i] >= 1)
      ans = max(ans, a[i]);
  }

  cout << ans << endl;

  return 0;
}
Problem p02359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

const int MAX = 100010;
int main() {
  using namespace std;
  int N, T;
  cin >> N >> T;
  int A[MAX] = {0};
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    A[a]++;
    A[b]--;
  }
  for (int i = 1; i <= T; i++) {
    ans = ans > A[i - 1] ? ans : A[i - 1];
    A[i] += A[i - 1];
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

const int MAX = 100010;
int main() {
  using namespace std;
  int N, T;
  cin >> N >> T;
  int A[MAX] = {0};
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j < b; j++) {
      A[j]++;
    }
  }
  for (int i = 0; i < T; i++) {
    ans = ans > A[i] ? ans : A[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02359 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  pair<int, int> a;
  int n, t;
  int table[200000] = {}, mx = 0, count = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a.first >> a.second;
    table[a.first] += 1;
    table[a.second] -= 1;
  }
  for (int i = 0; i <= t; i++) {
    count += table[i];
    mx = max(mx, count);
  }

  cout << mx << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  pair<int, int> a[200000];
  int n, t;
  int table[200000], mx = 0;
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
  }

  for (int i = 0; i < n; i++) {
    for (int t = a[i].first; t < a[i].second; t++) {
      table[t]++;
      if (table[t] > mx) {
        mx = table[t];
      }
    }
  }

  cout << mx << endl;

  return 0;
}
Problem p02360 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

struct Square {
  int x1, y1, x2, y2;
};
std::istream &operator>>(std::istream &is, Square &s) {
  return is >> s.x1 >> s.y1 >> s.x2 >> s.y2;
}
int main() {
  int n;
  std::cin >> n;
  constexpr int max_coord = 1000;
  std::vector<std::vector<int>> map(max_coord + 1,
                                    std::vector<int>(max_coord + 1, 0));
  Square s;
  for (auto i = 0; i < n; ++i) {
    std::cin >> s;
    map[s.x1][s.y1]++;
    map[s.x2][s.y1]--;
    map[s.x1][s.y2]--;
    map[s.x2][s.y2]++;
  }
  for (auto i = 1; i < map.size(); ++i) {
    for (auto j = 0; j < map[i].size(); ++j) {
      map[i][j] += map[i - 1][j];
    }
  }
  int max = 0;
  for (auto i = 0; i < map.size(); ++i) {
    if (max < map[i][0])
      max = map[i][0];
    for (auto j = 1; j < map[i].size(); ++j) {
      map[i][j] += map[i][j - 1];
      if (max < map[i][j])
        max = map[i][j];
    }
  }
  std::cout << max << std::endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

struct Square {
  int x1, y1, x2, y2;
};
std::istream &operator>>(std::istream &is, Square &s) {
  return is >> s.x1 >> s.y1 >> s.x2 >> s.y2;
}
int main() {
  int n;
  std::cin >> n;
  constexpr int max_coord = 4;
  std::vector<std::vector<int>> map(max_coord + 1,
                                    std::vector<int>(max_coord + 1, 0));
  Square s;
  for (auto i = 0; i < n; ++i) {
    std::cin >> s;
    map[s.x1][s.y1]++;
    map[s.x2][s.y1]--;
    map[s.x1][s.y2]--;
    map[s.x2][s.y2]++;
  }
  for (auto i = 1; i < map.size(); ++i) {
    for (auto j = 0; j < map[i].size(); ++j) {
      map[i][j] += map[i - 1][j];
    }
  }
  int max = 0;
  for (auto i = 0; i < map.size(); ++i) {
    if (max < map[i][0])
      max = map[i][0];
    for (auto j = 1; j < map[i].size(); ++j) {
      map[i][j] += map[i][j - 1];
      if (max < map[i][j])
        max = map[i][j];
    }
  }
  std::cout << max << std::endl;
}
Problem p02360 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main(void) {
  long long int N;

  long long int **field;
  field = new long long int *[1005];
  for (int i = 0; i < 1005; i++) {
    field[i] = new long long int[1005];
    for (int j = 0; j < 1005; j++)
      field[i][j] = 0;
  }

  cin >> N;
  int x1, y1, x2, y2;
  for (long long int i = 0; i < N; i++) {
    cin >> x1 >> y1 >> x2 >> y2;

    field[y1][x1]++;
    field[y1][x2]--;
    field[y2][x1]--;
    field[y2][x2]++;
  }

  long long int **result, **result2;
  result = new long long int *[1005];
  result2 = new long long int *[1005];
  for (int i = 0; i < 1005; i++) {
    result[i] = new long long int[1005];
    result2[i] = new long long int[1005];
    for (int j = 0; j < 1005; j++) {
      result[i][j] = 0;
      result2[i][j] = 0;
    }
  }

  int now;
  for (int y = 0; y < 1005; y++) {
    now = 0;
    for (int x = 0; x < 1005; x++) {
      now += field[y][x];
      result[y][x] += now;
    }
  }
  int max = 0;
  for (int x = 0; x < 1005; x++) {
    now = 0;
    for (int y = 0; y < 1005; y++) {
      now += result[y][x];
      result2[y][x] += now;
      if (max < result2[y][x])
        max = result2[y][x];
    }
  }
  cout << max << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  long long int N;

  long long int **field;
  field = new long long int *[1000];
  for (int i = 0; i < 1000; i++) {
    field[i] = new long long int[1000];
    for (int j = 0; j < 1000; j++)
      field[i][j] = 0;
  }

  cin >> N;
  int x1, y1, x2, y2;
  for (long long int i = 0; i < N; i++) {
    cin >> x1 >> y1 >> x2 >> y2;

    field[y1][x1]++;
    field[y1][x2]--;
    field[y2][x1]--;
    field[y2][x2]++;
  }

  long long int **result, **result2;
  result = new long long int *[1000];
  result2 = new long long int *[1000];
  for (int i = 0; i < 1000; i++) {
    result[i] = new long long int[1000];
    result2[i] = new long long int[1000];
    for (int j = 0; j < 1000; j++) {
      result[i][j] = 0;
      result2[i][j] = 0;
    }
  }

  int now;
  for (int y = 0; y < 1000; y++) {
    now = 0;
    for (int x = 0; x < 1000; x++) {
      now += field[y][x];
      result[y][x] += now;
    }
  }
  int max = 0;
  for (int x = 0; x < 1000; x++) {
    now = 0;
    for (int y = 0; y < 1000; y++) {
      now += result[y][x];
      result2[y][x] += now;
      if (max < result2[y][x])
        max = result2[y][x];
    }
  }
  cout << max << endl;
  /*
  for(int y=0;y<10;y++){
      for(int x=0;x<10;x++){
          cout << result2[y][x] << " ";
      }
      cout << endl;
  }
  */
  return 0;
}
Problem p02360 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int ix(int x, int y) { return (1001 * y) + x; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int R[1200000]{0};
  int n;
  cin >> n;

  for (int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;) {
    for (int y = y1; y < y2; ++y)
      R[ix(x1, y)]++;
    for (int y = y1; y < y2; ++y)
      R[ix(x2, y)]--;
  }

  int C[1000]{0};

  int M = 0;
  for (int x = 0; x < 1000; ++x) {
    for (int y = 0; y < 1000; ++y) {
      C[y] += R[ix(x, y)];
      M = max(M, C[y]);
    }
  }
  cout << M << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;

struct seg {
  // [start, end)
  int ylow;
  int yhi;
  int begin; // 1 for begin, -1 for end
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;

  map<int, vector<seg>> rects;
  map<int, int> counts;
  for (int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;) {
    rects[x1].push_back({y1, y2, 1});
    rects[x2].push_back({y1, y2, -1});
    counts[y1] = 0;
    counts[y2] = 0;
  }

  int M = 0;
  vector<int> modified;
  for (auto &entry : rects) {
    int ymin = entry.second[0].ylow, ymax = 0;
    int y;
    modified.clear();
    for (seg &s : entry.second) {
      for (auto it = counts.lower_bound(s.ylow);
           it != counts.end() && (y = it->first) < s.yhi; ++it) {
        ymax = max(ymax, s.yhi);
        counts[y] += s.begin;
        modified.push_back(y);
      }
    }
    for (int ym : modified)
      M = max(M, counts[ym]);
  }
  cout << M << endl;
}
Problem p02360 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

int a[1001][1001];

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    a[x1][y1]++;
    a[x1][y2]--;
    a[x2][y1]--;
    a[x2][y2]++;
  }

  for (int i = 0; i < 1001; i++)
    for (int j = 1; j < 1001; j++) {
      a[i][j] += a[i][j - 1];
    }
  for (int i = 1; i < 1001; i++)
    for (int j = 0; j < 1001; j++) {
      a[i][j] += a[i - 1][j];
    }

  int maxi = 0;
  for (int i = 0; i < 1001; i++)
    for (int j = 0; j < 1001; j++) {
      maxi = max(maxi, a[i][j]);
    }
  printf("%d\\n", maxi);
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <map>
#include <math.h>

#define SENTINEL 1000000001

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

int a[1001][1001];

int main() {
  int N;
  cin >> N;

  int maxi = 0;
  for (int i = 0; i < N; i++) {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    for (int i = x1; i < x2; i++)
      for (int j = y1; j < y2; j++) {
        a[i][j]++;
        maxi = max(maxi, a[i][j]);
      }
  }

  printf("%d\\n", maxi);
}
Problem p02361 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#include <vector>
#define INF 1000000001
using namespace std;
struct E {
  int rel, cost;
};
vector<E> grh[100000];
int v, e, r;

void dijkstra() {

  priority_queue<pair<int, int>> Q;
  int sum = 0;
  int d[100000];
  for (int i = 0; i < v; i++)
    d[i] = INF;
  d[r] = 0;
  Q.push(make_pair(0, r));
  int s, f;
  while (!Q.empty()) {
    f = Q.top().first;
    s = Q.top().second;
    Q.pop();
    for (int i = 0; i < grh[s].size(); i++) {
      E e = grh[s][i];
      if (d[e.rel] > e.cost - f) {
        d[e.rel] = e.cost - f;
        Q.push(make_pair(-d[e.rel], e.rel));
      }
    }
  }
  for (int i = 0; i < v; i++) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
}

int main() {
  cin >> v >> e >> r;
  int a, b, c;
  for (int i = 0; i < e; i++) {
    cin >> a >> b >> c;
    grh[a].push_back((E){b, c});
  }
  dijkstra();

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
const int INF = 10001;

int main() {
  int V = 0; // num of vertices
  int E = 0; // num of edges
  int r = 0; // source node
  // input V, E, r
  cin >> V >> E >> r;

  int **G = new int *[V]; // 2 dim array to memorize distances
  for (int i = 0; i < V; i++) {
    G[i] = new int[V];
  }
  // initiate G
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      G[i][j] = INF;
    }
  }
  for (int i = 0; i < V; i++) {
    G[i][i] = 0;
  }

  // input G
  int src = 0;
  int tar = 0;
  int dis = 0;
  for (int i = 0; i < E; i++) {
    cin >> src >> tar >> dis;
    G[src][tar] = dis;
  }

  // start dijkstra
  vector<int> *U = new vector<int>();
  U->push_back(r);
  bool *valid = new bool[V];
  for (int i = 0; i < V; i++) {
    valid[i] = true;
  }
  valid[r] = false;

  int min = INF; // record the min-distance
  int ver = V;   // record the min-distance-vertice
  while (U->size() < V) {
    min = INF;
    ver = V;
    for (int i = 0; i < V; i++) {
      if (G[r][i] < min && valid[i]) {
        min = G[r][i];
        ver = i;
      }
    }
    if (V == ver) {
      break;
    }

    U->push_back(ver);
    valid[ver] = false;
    for (int i = 0; i < V; i++) {
      if (i != r && G[r][ver] + G[ver][i] < G[r][i]) {
        G[r][i] = G[r][ver] + G[ver][i];
      }
    }
  }

  // output
  for (int i = 0; i < V; i++) {
    if (INF == G[r][i]) {
      cout << "INF" << endl;
    } else {
      cout << G[r][i] << endl;
    }
  }

  // delete
  for (int i = 0; i < V; i++) {
    delete[] G[i];
  }
  delete[] G;
  delete[] valid;

  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
using namespace std;

typedef pair<int, int> P;

vector<P> edge[100000];
priority_queue<P, vector<P>, greater<P>> que;
int cost[100000];
int V, E, r;
const int INF = 999999999;

int main() {
  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int from, to, d;
    cin >> from >> to >> d;
    edge[from].push_back(P(to, d));
  }

  for (int i = 0; i < 100000; i++) {
    cost[i] = INF;
  }

  cost[r] = 0;
  que.push(P(r, 0));

  while (!que.empty()) {
    P now = que.top();
    que.pop();

    for (int i = 0; i < edge[now.first].size(); i++) {
      int to = edge[now.first][i].first;
      int c = now.second + edge[now.first][i].second;
      if (cost[to] > c) {
        cost[to] = c;
        que.push(P(to, c));
      }
    }
  }

  for (int i = 0; i < V; i++) {
    if (cost[i] == INF) {
      cout << "INF" << endl;
      continue;
    }
    cout << cost[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
using namespace std;

typedef pair<int, int> P;

map<P, int> edge;
priority_queue<P, vector<P>, greater<P>> que;
int cost[100000];
int V, E, r;
const int INF = 999999999;

int main() {
  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int from, to, d;
    cin >> from >> to >> d;
    edge[P(from, to)] = d;
  }

  for (int i = 0; i < 100000; i++) {
    cost[i] = INF;
  }

  cost[r] = 0;
  que.push(P(r, 0));

  while (!que.empty()) {
    P now = que.top();
    que.pop();

    for (int i = 0; i < V; i++) {
      if (i == now.first)
        continue;
      if (edge.count(P(now.first, i))) {
        int c = now.second + edge[P(now.first, i)];
        if (cost[i] > c) {
          cost[i] = c;
          que.push(P(i, c));
        }
      }
    }
  }

  for (int i = 0; i < V; i++) {
    if (cost[i] == INF) {
      cout << "INF" << endl;
      continue;
    }
    cout << cost[i] << endl;
  }

  return 0;
}