alexjercan/bugnet huggingface dataset:
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define INF 1 << 21
using namespace std;
int d[128][128];
int N, M;

void warshall_floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main() {
  while (1) {
    int s, g1, g2;
    cin >> N >> M >> s >> g1 >> g2;

    if (!N && !M && !s && !g1 && !g2)
      break;
    s--;
    g1--;
    g2--;
    for (int i = 0; i < N; i++) {
      fill_n(d[i], N, INF);
    }
    for (int i = 0; i < N; i++) {
      d[i][i] = 0;
    }
    for (int i = 0; i < M; i++) {
      int u, v, c;
      cin >> u >> v >> c;
      u--;
      v--;
      d[u][v] = c;
    }

    warshall_floyd();
    int res = INF;
    for (int i = 0; i < N; i++) {
      res = min(res, d[s][i] + d[i][g1] + d[i][g2]);
    }
    cout << res << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define INF 1 << 21
using namespace std;
int d[100][100];
int N, M;

void warshall_floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main() {
  while (1) {
    int s, g1, g2;
    cin >> N >> M >> s >> g1 >> g2;
    if (!N && !M && !s && !g1 && !g2)
      break;
    for (int i = 0; i < N; i++) {
      fill_n(d[i], N, INF);
    }
    for (int i = 0; i < M; i++) {
      int u, v, c;
      cin >> u >> v >> c;
      d[u][v] = c;
      d[v][u] = c;
    }
    warshall_floyd();
    int res = INF;
    for (int i = 0; i < N; i++) {
      res = min(res, d[s][i] + d[i][g1] + d[i][g2]);
    }
    cout << res << endl;
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int INF = 1 << 21;
int main() {
  int n, m, s, g1, g2;
  int b1, b2, c;
  int ans = INF;
  int road[111][111];
  while (1) {
    cin >> n >> m >> s >> g1 >> g2;
    if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
      break;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        road[i][j] = INF;
      }
      road[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
      cin >> b1 >> b2 >> c;
      road[b1][b2] = c;
    }
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      ans = min(ans, road[s][i] + road[i][g1] + road[i][g2]);
    }
    cout << ans << endl;
    ans = INF;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int INF = 1 << 21;
int main() {
  int n, m, s, g1, g2;
  int b1, b2, c;
  int ans = INF;
  int road[111][111];
  for (int i = 0; i < 111; i++) {
    for (int j = 0; j < 111; j++) {
      road[i][j] = INF;
    }
  }
  while (1) {
    cin >> n >> m >> s >> g1 >> g2;
    if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
      break;
    for (int i = 0; i < m; i++) {
      cin >> b1 >> b2 >> c;
      road[b1][b2] = c;
    }
    for (int k = 1; k <= n; k++) {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          road[i][j] = min(road[i][j], road[i][k] + road[k][j]);
        }
      }
    }
    for (int i = 1; i <= m; i++) {
      ans = min(ans, road[s][i] + road[i][g1] + road[i][g2]);
    }
    cout << ans << endl;
    ans = INF;
  }
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int V, E, S, G1, G2, B1, B2, C;

vector<vector<int>> G;

vector<vector<int>> R;

void Shortest(int s, int mode, int rev) {
  vector<bool> u(V, false);

  R[mode][s] = 0;

  while (true) {
    int v = -1, c = 99999999;

    for (int i = 0; i < V; i++) {
      if (!u[i] && R[mode][i] < c) {
        c = R[mode][i];
        v = i;
      }
    }

    if (c == 99999999) {
      break;
    }

    u[v] = true;

    for (int i = 0; i < V; i++) {
      if (!u[i]) {
        if (R[mode][i] > R[mode][v] + (rev ? G[i][v] : G[v][i])) {
          R[mode][i] = R[mode][v] + (rev ? G[i][v] : G[v][i]);
        }
      }
    }
  }
}

int main() {
  while (true) {
    cin >> V >> E >> S >> G1 >> G2;

    if (V == 0) {
      break;
    }

    G = vector<vector<int>>(V, vector<int>(V, 99999999));

    for (int i = 0; i < E; i++) {
      cin >> B1 >> B2 >> C;

      G[B1 - 1][B2 - 1] = C;
    }

    R = vector<vector<int>>(3, vector<int>(V, 99999999));

    Shortest(S - 1, 0, 0);
    Shortest(G1 - 1, 1, 1);
    Shortest(G2 - 1, 2, 1);

    int ret = 299999997;

    for (int i = 0; i < V; i++) {
      ret = min(ret, R[0][i] + R[1][i] + R[2][i]);
    }

    cout << ret << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

int V, E, S, G1, G2, B1, B2, C;

vector<vector<int>> G;

vector<vector<int>> R;

void Shortest(int s, int mode, int rev) {
  vector<bool> u(V, false);
  R[mode][s] = 0;

  while (true) {
    int v = -1, c = 99999999;

    for (int i = 0; i < V; i++) {
      if (!u[i] && R[mode][i] < c) {
        c = R[mode][i];
        v = i;
      }
    }

    if (c == 99999999) {
      break;
    }

    u[v] = true;

    for (int i = 0; i < V; i++) {
      if (!u[v]) {
        if (R[mode][i] > R[mode][v] + (rev ? G[i][v] : G[v][i])) {
          R[mode][i] = R[mode][v] + (rev ? G[i][v] : G[v][i]);
        }
      }
    }
  }
}

int main() {
  int V, E, S, G1, G2, B1, B2, C;

  while (true) {
    cin >> V >> E >> S >> G1 >> G2;

    if (V == 0) {
      break;
    }

    G = vector<vector<int>>(V, vector<int>(V, 99999999));

    for (int i = 0; i < E; i++) {
      cin >> B1 >> B2 >> C;

      G[B1 - 1][B2 - 1] = C;
    }

    R = vector<vector<int>>(3, vector<int>(V, 99999999));

    Shortest(S, 0, 0);
    Shortest(G1, 1, 1);
    Shortest(G2, 2, 1);

    int ret = 299999997;

    for (int i = 0; i < V; i++) {
      ret = min(ret, R[0][i] + R[1][i] + R[2][i]);
    }

    cout << ret << endl;
  }

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

#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INF 0x1FFFFFFF

using namespace std;

int main(void) {
  int n, m, s, c, g1, g2, b1, b2, i, j, k, ans, w[100][100];
  while (1) {
    scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2);
    if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
      break;
    s--, g1--, g2--;

    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++)
        w[i][j] = INF;
      w[i][i] = 0;
    }

    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &b1, &b2, &c);
      w[b1 - 1][b2 - 1] = c;
    }

    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < n; k++)
          w[j][k] = min(w[j][k], w[j][i] + w[i][k]);
      }
    }
    ans = INF;
    for (i = 0; i < n; i++) {
      ans = min(ans, w[s][i] + w[i][g1] + w[i][g2]);
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
  int from;
  int to;
  int cost;
} edge;

int cmp(const void *a, const void *b) {
  edge *e1 = (edge *)a;
  edge *e2 = (edge *)b;
  return e1->cost - e2->cost;
}
int t[100], r[100];
void init(int n) {
  int i;
  for (i = 0; i < n; i++) {
    t[i] = i;
    r[i] = 0;
  }
}

int find(int x) {
  if (x == t[x])
    return x;
  else
    return t[x] = find(t[x]);
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (r[x] > r[y])
    t[y] = x;
  else if (r[x] < r[y])
    t[x] = y;
  else if (x != y) {
    t[y] = x;
    r[x]++;
  }
}

int main(void) {
  int n, m, s, c, g1, g2, b1, b2, i, j, k, a, sum, v[100];
  edge e[1000], tmp;
  while (1) {
    scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2);
    if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
      break;
    s--, g1--, g2--;

    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &b1, &b2, &c);
      e[i].from = b1 - 1, e[i].to = b2 - 1, e[i].cost = c;
    }
    qsort(e, m, sizeof(e[0]), cmp);
    init(n);
    a = m;
    for (i = 0; i < m && a != 1; i++) {
      if (find(e[i].from) != find(e[i].to))
        unite(e[i].from, e[i].to);
      else {
        for (j = i; j < m - 1; j++)
          e[i] = e[i + 1];
        m--;
      }
      a = 0;
      for (j = 0; j < n; j++)
        if (t[j] == j)
          a++;
    }
    m = i;
    memset(v, 0, sizeof(v));
    for (i = 0; i < m; i++)
      v[e[i].from]++, v[e[i].to]++;
    while (v[s] != 1 || v[g1] != 1 || v[g2] != 1) {
      for (i = 0; i < m; i++) {
        if ((v[e[i].from] == 1 || v[e[i].to] == 1) &&
            (e[i].from == g1 || e[i].to == g1 || e[i].from == g2 ||
             e[i].to == g2 || e[i].from == s || e[i].to == s)) {
          for (j = i; j < m - 1; j++)
            e[i] = e[i + 1];
          m--;
        }
      }
      memset(v, 0, sizeof(v));
      for (i = 0; i < m; i++)
        v[e[i].from]++, v[e[i].to]++;
    }
    sum = 0;
    for (i = 0; i < m; i++)
      sum += e[i].cost;
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

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

template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}

constexpr int MAX_N = 100;
constexpr int INF = (1 << 29);
int dist[MAX_N][MAX_N];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  for (int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2 && n;) {
    --s;
    --g1;
    --g2;
    fill_n((int *)dist, sizeof(dist) / sizeof(int), INF);

    for (int i = 0; i < n; ++i) {
      dist[i][i] = 0;
    }

    for (int i = 0; i < m; ++i) {
      int from, to, cost;
      cin >> from >> to >> cost;
      dist[from - 1][to - 1] = cost;
    }

    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          chmin(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int ans = INF;
    for (int i = 0; i < n; ++i) {
      chmin(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
    }

    assert(ans != INF);
    cout << ans << endl;
  }

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

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

template <class T> inline void chmin(T &a, const T &b) {
  if (a > b)
    a = b;
}

constexpr int MAX_N = 100;
constexpr int INF = (1 << 29);
int dist[MAX_N][MAX_N];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  for (int n, m, s, g1, g2; cin >> n >> m >> s >> g1 >> g2 && n;) {
    --s;
    --g1;
    --g2;
    fill_n((int *)dist, sizeof(dist) / sizeof(int), INF);

    for (int i = 0; i < m; ++i) {
      int from, to, cost;
      cin >> from >> to >> cost;
      dist[from - 1][to - 1] = cost;
    }

    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          chmin(dist[i][j], dist[i][k] + dist[k][j]);
        }
      }
    }

    int ans = INF;
    for (int i = 0; i < n; ++i) {
      chmin(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
    }

    assert(ans != INF);
    cout << ans << endl;
  }

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


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

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define INF (1 << 28)
#define mk make_pair
#define fs first
#define sc second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, m, s, g, h;

int v[100][100];

template <class T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "{";
  rep(i, v.size()) out << v[i] << ",";
  out << "}" << endl;
}

int main() {
  while (cin >> n >> m >> s >> g >> h, n) {
    rep(i, 100) rep(j, 100) v[i][j] = i == j ? 0 : INF;
    int ans = INF;
    s--;
    g--;
    h--;
    rep(i, m) {
      int x, y, c;
      cin >> x >> y >> c;
      v[x - 1][y - 1] = c;
    }

    rep(k, n) rep(i, n) rep(j, n) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);

    rep(i, n) { ans = min(ans, v[s][i] + v[i][g] + v[i][h]); }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:


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

#define reps(i, j, k) for (int i = (j); i < (k); i++)
#define rep(i, j) reps(i, 0, j)
#define INF (1 << 28)
#define mk make_pair
#define fs first
#define sc second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, m, s, g, h;
vector<vi> v;

template <class T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "{";
  rep(i, v.size()) out << v[i] << ",";
  out << "}" << endl;
}

int main() {
  while (cin >> n >> m >> s >> g >> h, n) {
    v.resize(n, vi(n, INF));
    int ans = INF;
    s--;
    g--;
    h--;
    rep(i, m) {
      int x, y, c;
      cin >> x >> y >> c;
      v[x - 1][y - 1] = c;
    }

    rep(k, n) rep(i, n) rep(j, n) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);

    rep(i, n) { ans = min(ans, v[s][i] + v[i][g] + v[i][h]); }
    cout << ans << endl;
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

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

#define INF 10000001

#define MAX_SIZE 101
long long g_d[MAX_SIZE][MAX_SIZE];
void warshall_floyd(int v) {
  for (int k = 0; k < v; ++k) {
    for (int i = 0; i < v; ++i) {
      for (int j = 0; j < v; ++j) {
        g_d[i][j] = min(g_d[i][j], g_d[i][k] + g_d[k][j]);
      }
    }
  }
}

int main() {

  while (true) {
    int n, m, s, g1, g2;
    cin >> n >> m >> s >> g1 >> g2;
    --s;
    --g1;
    --g2;
    if (n == 0)
      break;

    fill(g_d[0], g_d[0] + MAX_SIZE * MAX_SIZE, INF);
    for (int i = 0; i < MAX_SIZE; ++i) {
      g_d[i][i] = 0;
    }

    for (int i = 0; i < m; ++i) {
      int b1, b2;
      cin >> b1 >> b2;
      --b1;
      --b2;
      cin >> g_d[b1][b2];
    }

    warshall_floyd(n);

    long long cost = INF;
    for (int i = 0; i < n; ++i) {
      cost = min(cost, g_d[s][i] + g_d[i][g1] + g_d[i][g2]);
    }

    cout << cost << endl;
  }
}

Error: TLE

Fixed submission:

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

#define INF 10000001

#define MAX_SIZE 101
long long g_d[MAX_SIZE][MAX_SIZE];
void warshall_floyd(int v) {
  for (int k = 0; k < v; ++k) {
    for (int i = 0; i < v; ++i) {
      for (int j = 0; j < v; ++j) {
        g_d[i][j] = min(g_d[i][j], g_d[i][k] + g_d[k][j]);
      }
    }
  }
}

int main() {
  freopen("Text.txt", "r", stdin);

  while (true) {
    int n, m, s, g1, g2;
    cin >> n >> m >> s >> g1 >> g2;
    --s;
    --g1;
    --g2;
    if (n == 0)
      break;

    fill(g_d[0], g_d[0] + MAX_SIZE * MAX_SIZE, INF);
    for (int i = 0; i < MAX_SIZE; ++i) {
      g_d[i][i] = 0;
    }

    for (int i = 0; i < m; ++i) {
      int b1, b2;
      cin >> b1 >> b2;
      --b1;
      --b2;
      cin >> g_d[b1][b2];
    }

    warshall_floyd(n);

    long long cost = INF;
    for (int i = 0; i < n; ++i) {
      cost = min(cost, g_d[s][i] + g_d[i][g1] + g_d[i][g2]);
    }

    cout << cost << endl;
  }
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> Vec;
#define INF 20000000

void war(Vec &vec) {
  int v = vec.size();
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        vec[i][j] = min(vec[i][j], vec[i][k] + vec[k][j]);
      }
    }
  }
}

int main() {
  while (1) {
    int n, m, s, g1, g2, a, b, c;
    cin >> n >> m >> s >> g1 >> g2;
    s--;
    g1--;
    g2--;
    if (!n)
      break;
    Vec G(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        G[i].push_back(i != j ? INF : 0);
      }
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      G[a - 1][b - 1] = c;
    }
    war(G);
    int res = INF;
    for (int i = 0; i < n; i++) {
      res = min(res, G[s][i] + G[i][g1] + G[i][g2]);
    }
    cout << res << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<vector<int>> Vec;
#define INF 20000000

void war(Vec &vec) {
  int v = vec.size();
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        vec[i][j] = min(vec[i][j], vec[i][k] + vec[k][j]);
      }
    }
  }
}

int main() {
  while (1) {
    int n, m, s, g1, g2, a, b, c;
    Vec G(n);
    cin >> n >> m >> s >> g1 >> g2;
    s--;
    g1--;
    g2--;
    if (!n)
      break;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        G[i].push_back(i != j ? INF : 0);
      }
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c;
      G[a - 1][b - 1] = c;
    }
    war(G);
    int res = INF;
    for (int i = 0; i < n; i++) {
      res = min(res, G[s][i] + G[i][g1] + G[i][g2]);
    }
    cout << res << endl;
  }
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

const int kN = 105;
int atl[kN][kN];

void warshallFloyd(int n) {
  range(k, 1, n + 1) {
    range(i, 1, n + 1) {
      range(j, 1, n + 1) { atl[i][j] = min(atl[i][j], atl[i][k] + atl[k][j]); }
    }
  }
}

int requestCost(int n, int s, int g1, int g2) {
  int retval = INF;
  range(i, 1, n + 1) {
    int cost = atl[s][i] + atl[i][g1] + atl[i][g2];
    retval = min(retval, cost);
  }
  return retval;
}

int main() {
  int n, m, s, g1, g2;
  while (cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2) {
    rep(i, kN) rep(j, kN) atl[i][j] = INF;
    rep(i, kN) atl[i][i] = 0;
    rep(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      atl[a][b] = c;
    }
    warshallFloyd(n);
    cout << requestCost(n, s, g1, g2) << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

const int kN = 100;
int atl[kN][kN];

void warshallFloyd(int n) {
  range(k, 1, n + 1) {
    range(i, 1, n + 1) {
      range(j, 1, n + 1) { atl[i][j] = min(atl[i][j], atl[i][k] + atl[k][j]); }
    }
  }
}

int requestCost(int n, int s, int g1, int g2) {
  int retval = INF;
  rep(i, n) {
    int cost = atl[s][i] + atl[i][g1] + atl[i][g2];
    retval = min(retval, cost);
  }
  return retval;
}

int main() {
  int n, m, s, g1, g2;
  while (cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2) {
    rep(i, kN) rep(j, kN) atl[i][j] = INF;
    rep(i, m) {
      int a, b, c;
      cin >> a >> b >> c;
      atl[a][b] = c;
    }
    warshallFloyd(n);
    cout << requestCost(n, s, g1, g2) << endl;
  }
}
Problem p01130 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef long long int Int;
typedef pair<int, int> P;
const int MAX_N = 105;
const int INF = 1e9;

int main() {
  Int G[MAX_N][MAX_N], N, M, S, G1, G2;
  while (cin >> N >> M >> S >> G1 >> G2 && N) {
    --S;
    --G1;
    --G2;
    REP(i, N) REP(j, N) G[i][j] = (i == j ? 0 : INF);
    REP(i, M) {
      int f, t, c;
      cin >> f >> t >> c;
      G[f - 1][t - 1] = c;
    }
    Int ans = INF;
    REP(k, N) REP(i, N) REP(j, N) G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    REP(i, N) ans = min(ans, G[S][i] + G[i][G1] + G[i][G2]);
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 110;
const int INF = 1e9 + 7;

class C {
public:
  int from, to, cost;
  bool d;
  C() {}
  C(int _f, int _t, int _c, bool _d) {
    from = _f;
    to = _t;
    cost = _c;
    d = _d;
  }
  bool operator<(const C &c) const { return cost < c.cost; }
};

bool dfs(int now, int t, int c, vector<int> &cost, vector<C> &es) {
  cost[now] = c;
  if (now == t)
    return true;
  bool res = false;
  REP(i, es.size()) {
    if (es[i].d || es[i].from != now || c + es[i].cost >= cost[es[i].to])
      continue;
    res = max(res, dfs(es[i].to, t, c + es[i].cost, cost, es));
  }
  return res;
}

int main() {
  int N, M, S, G1, G2;
  while (cin >> N >> M >> S >> G1 >> G2 && N) {
    --S;
    --G1;
    --G2;
    vector<C> es(M);
    int sum = 0;
    REP(i, M) {
      int f, t, c;
      cin >> f >> t >> c;
      --f;
      --t;
      es.push_back(C(f, t, c, 0));
      sum += c;
    }
    SORT(es);
    REVERSE(es);
    REP(i, M) {
      es[i].d = true;
      vector<int> cost(N, INF), cost2(N, INF);
      if (dfs(S, G1, 0, cost, es) && dfs(S, G2, 0, cost2, es))
        sum -= es[i].cost;
      else
        es[i].d = false;
    }
    cout << sum << endl;
  }
  return 0;
}