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

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

int N, n;
int H, W;

char m[50][50];
bool used[26];
int U[26], D[26], L[26], R[26];

bool check(char ch) {
  int z = ch - 'A';
  for (int i = U[z]; i <= D[z]; ++i) {
    for (int j = L[z]; j <= R[z]; ++j) {
      if (m[i][j] != '.' && used[m[i][j] - 'A'] == false)
        continue;
      if (m[i][j] != ch)
        return false;
    }
  }
  return true;
}
void input() {
  int x;
  string str;
  cin >> H >> W;
  rep(i, H) {
    cin >> str;
    rep(j, W) {
      m[i][j] = str[j];
      if (m[i][j] == '.')
        continue;
      x = m[i][j] - 'A';
      used[x] = true;
      U[x] = min(U[x], i);
      D[x] = max(D[x], i);
      L[x] = min(L[x], j);
      R[x] = max(R[x], j);
    }
  }
}

void init() {
  rep(i, 26) {
    U[i] = 50;
    D[i] = 0;
    L[i] = 50;
    R[i] = 0;
    used[i] = false;
  }
}
int main() {
  cin >> N;
  while (N--) {
    init();
    input();
    while (1) {
      bool flag = false;
      rep(i, 26) {
        if (used[i] == false)
          continue;
        if (check(i + 'A') == true) {
          used[i] = false;
          flag = true;
          break;
        }
      }
      if (flag == false)
        break;
    }
    bool flag = false;
    rep(i, 26) flag |= used[i];
    cout << (flag ? "SUSPICIOUS" : "SAFE") << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

int N, n;
int H, W;

char m[50][50];
bool used[26];
int U[26], D[26], L[26], R[26];

bool check(char ch) {
  int z = ch - 'A';
  for (int i = U[z]; i < D[z]; ++i) {
    for (int j = L[z]; j < R[z]; ++j) {
      if (m[i][j] != '.' && used[z] == false)
        continue;
      if (m[i][j] != ch)
        return false;
    }
  }
  return true;
}
void input() {
  int x;
  string str;
  cin >> H >> W;
  rep(i, H) {
    cin >> str;
    rep(j, W) {
      m[i][j] = str[j];
      if (m[i][j] == '.')
        continue;
      x = m[i][j] - 'A';
      used[x] = true;
      U[x] = min(U[x], i);
      D[x] = max(D[x], i);
      L[x] = min(L[x], j);
      R[x] = max(R[x], j);
    }
  }
}

void init() {
  rep(i, 26) {
    U[i] = 50;
    D[i] = 0;
    L[i] = 50;
    R[i] = 0;
    used[i] = false;
  }
}
int main() {
  cin >> N;
  while (N--) {
    init();
    input();
    while (1) {
      bool flag = false;
      rep(i, 26) {
        if (used[i] == false)
          continue;
        if (check(i + 'A') == true) {
          used[i] = false;
          flag = true;
          break;
        }
      }
      flag = false;
      rep(i, 26) flag |= used[i];
      cout << (flag ? "SUSPICIOUS" : "SAFE") << endl;
    }
  }
  return 0;
}
Problem p01127 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  int n;
  cin >> n;
  REP(_, n) {
    int h, w;
    cin >> h >> w;
    if (!h)
      return 0;
    vector<string> sc;
    sc.resize(h);
    REP(i, h) cin >> sc[i];
    set<char> car;
    car.clear();
    REP(i, h) REP(j, w) if (sc[i][j] != '.') car.insert(sc[i][j]);
    vector<char> carv(car.begin(), car.end());
    string answer = "SUSPICIOUS";
    map<char, int> u, d, l, r;
    REP(dep, carv.size()) {
      u[carv[dep]] = 100;
      d[carv[dep]] = -1;
      l[carv[dep]] = 100;
      r[carv[dep]] = -1;
    }
    REP(dep, carv.size()) REP(i, h) REP(j, w) if (sc[i][j] == carv[dep]) {
      u[carv[dep]] = min(u[carv[dep]], i);
      d[carv[dep]] = max(d[carv[dep]], i);
      l[carv[dep]] = min(l[carv[dep]], j);
      r[carv[dep]] = max(r[carv[dep]], j);
    }
    do {
      vector<string> prob;
      prob.resize(h);
      REP(i, h) prob[i].assign(w, '.');
      REP(dep, carv.size()) {
        FOR(i, u[carv[dep]], d[carv[dep]] + 1)
        FOR(j, l[carv[dep]], r[carv[dep]] + 1) {
          prob[i][j] = carv[dep];
        }
      }
      bool flag = true;
      REP(i, h) if (sc[i] != prob[i]) flag = false;
      if (flag) {
        answer = "SAFE";
        break;
      }
    } while (next_permutation(carv.begin(), carv.end()));
    cout << answer << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;
int main(void) {
  int n;
  cin >> n;
  REP(_, n) {
    int h, w;
    cin >> h >> w;
    if (!h)
      return 0;
    vector<string> sc;
    sc.resize(h);
    REP(i, h) cin >> sc[i];
    set<char> car;
    car.clear();
    REP(i, h) REP(j, w) if (sc[i][j] != '.') car.insert(sc[i][j]);
    vector<char> carv(car.begin(), car.end());
    string answer = "SUSPICIOUS";
    do {
      vector<string> prob;
      prob.resize(h);
      REP(i, h) prob[i].assign(w, '.');
      REP(dep, carv.size()) {
        int u = 100, d = -1, l = 100, r = -1;
        REP(i, h) REP(j, w) if (sc[i][j] == carv[dep]) {
          u = min(u, i);
          d = max(d, i);
          l = min(l, j);
          r = max(r, j);
        }
        FOR(i, u, d + 1) FOR(j, l, r + 1) { prob[i][j] = carv[dep]; }
      }
      bool flag = true;
      REP(i, h) if (sc[i] != prob[i]) flag = false;
      if (flag) {
        answer = "SAFE";
        break;
      }
    } while (next_permutation(carv.begin(), carv.end()));
    cout << answer << endl;
  }
}
Problem p01128 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define y1 y114514
using namespace std;
typedef complex<double> P;
typedef pair<double, int> Pair;

int u, n;
double xa, ya, xb, yb;
double x1, y1, x2, y2;
int o, l;
vector<Pair> v;

double cross(P a, P b) { return (a.real() * b.imag() - a.imag() * b.real()); }

int is_intersected_ls(P a1, P a2, P b1, P b2) {
  if ((a1.real() - a2.real()) * (b1.imag() - b2.imag()) + EPS >
          (a1.imag() - a2.imag()) * (b1.real() - b2.real()) &&
      (a1.real() - a2.real()) * (b1.imag() - b2.imag()) <
          EPS + (a1.imag() - a2.imag()) * (b1.real() - b2.real()))
    return 0;
  return (cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS) &&
         (cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS);
}

P intersection_ls(P a1, P a2, P b1, P b2) {
  P b = b2 - b1;
  double d1 = abs(cross(b, a1 - b1));
  double d2 = abs(cross(b, a2 - b1));
  double t = d1 / (d1 + d2);
  return a1 + (a2 - a1) * t;
}

int main() {
  P a, b;
  scanf("%d", &u);
  rep(i, u) {
    cin >> xa >> ya >> xb >> yb;
    a = P(xa, ya);
    b = P(xb, yb);
    cin >> n;
    rep(j, n) {
      cin >> x1 >> y1 >> x2 >> y2 >> o >> l;
      if (l == 0)
        o = o ^ 1;
      P c = P(x1, y1), d = P(x2, y2);
      if (is_intersected_ls(a, b, c, d) == 0)
        continue;
      P e = intersection_ls(a, b, c, d);
      v.push_back(
          Pair(pow(e.real() - a.real(), 2) + pow(e.imag() - a.imag(), 2), o));
    }
    sort(v.begin(), v.end());
    int ans = 0;
    int st = 0;
    int cnt = 0;
    rep(j, v.size()) {
      if (st != v[j].second) {
        st = st ^ 1;
        cnt++;
      }
    }
    ans = cnt;
    cnt = 0;
    st = 1;
    rep(j, v.size()) {
      if (st != v[j].second) {
        st = st ^ 1;
        cnt++;
      }
    }
    ans = min(ans, cnt);
    cout << ans << endl;
    v.clear();
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int dp[11][100001];
int n, d, x;
int p[10][10];

int main() {
  cin >> n >> d >> x;
  rep(i, d) rep(j, n) cin >> p[i][j];
  rep(i, d) rep(j, 100001) dp[i][j] = j;
  for (int i = d - 2; i >= 0; i--) {
    for (int j = 1; j <= 100000; j++) {
      dp[i][j] = max(dp[i][j], dp[i + 1][j]);
      dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1);
      rep(k, n) {
        if (p[i][k] > j)
          continue;
        for (int l = i + 1; l < d; l++) {
          if (p[i][k] >= p[l][k])
            continue;
          cout << p[l][k] + dp[i][j - p[i][k]] << endl;
          dp[i][j] = max(dp[i][j], dp[l][p[l][k] + dp[i][j - p[i][k]]]);
        }
      }
    }
  }
  cout << dp[0][x] << endl;
}
Problem p01128 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef complex<double> P;
double det(const P &a, const P &b) { return (conj(b) * a).imag(); }
double ratio(P s1, P d1, P s2, P d2) { return det(s2 - s1, d2) / det(d1, d2); }
int main() {
  int c;
  cin >> c;
  while (c--) {
    int n, xa, ya, xb, yb, o, l;
    cin >> xa >> ya >> xb >> yb >> n;
    P a(xa, ya), b(xb, yb);
    vector<pair<double, int>> cross;
    rep(i, n) {
      cin >> xa >> ya >> xb >> yb >> o >> l;
      P c(xa, ya), d(xb, yb);
      double s = ratio(a, b - a, c, d - c), t = ratio(c, d - c, a, b - a);
      if (0 < s && s < 1 && 0 < t && t < 1)
        cross.push_back(make_pair(s, o ^ l));
    }
    sort(cross.begin(), cross.end());
    int ans = 0;
    n = cross.size();
    if (n > 1)
      rep(i, n - 1) if (cross[i].second != cross[i + 1].second) ans++;
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <complex>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef complex<double> P;
double det(const P &a, const P &b) { return (conj(b) * a).imag(); }
double ratio(P s1, P d1, P s2, P d2) { return det(s2 - s1, d2) / det(d1, d2); }
int main() {
  int c;
  cin >> c;
  while (c--) {
    int n, xa, ya, xb, yb, o, l;
    cin >> xa >> ya >> xb >> yb >> n;
    P a(xa, ya), b(xb, yb);
    vector<pair<double, int>> cross;
    rep(i, n) {
      cin >> xa >> ya >> xb >> yb >> o >> l;
      P c(xa, ya), d(xb, yb);
      double s = ratio(a, b - a, c, d - c), t = ratio(c, d - c, a, b - a);
      if (0 < s && s < 1 && 0 < t && t < 1)
        cross.push_back(make_pair(s, o ^ l ^ 1));
    }
    sort(cross.begin(), cross.end());
    int ans = 0;
    rep(i, cross.size() - 1) if (cross[i].second != cross[i + 1].second) ans++;
    cout << ans << endl;
  }
  return 0;
}
Problem p01128 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define N 100
#define INFF 100.0

double f(int x1, int y1, int x2, int y2, int X1, int Y1, int X2, int Y2) {
  if ((Y1 - Y2) * (x1 - x2) == (X1 - X2) * (y1 - y2))
    return INFF;
  return (double)((X1 - X2) * (y2 - Y2) - (Y1 - Y2) * (x2 - X2)) /
         (double)((Y1 - Y2) * (x1 - x2) - (X1 - X2) * (y1 - y2));
}

int main() {
  int nn, n, xa, ya, xb, yb, p, ans;
  int xs, ys, xt, yt, o, l;
  map<double, int> tl;
  double t1, t2;
  map<double, int>::iterator it;
  cin >> nn;
  for (int q = 0; q < nn; ++q) {
    cin >> xa >> ya >> xb >> yb >> n;
    tl.clear();
    ans = 0;
    for (int i = 0; i < n; ++i) {
      cin >> xs >> ys >> xt >> yt >> o >> l;
      t1 = f(xa, ya, xb, yb, xs, ys, xt, yt);
      t2 = f(xs, ys, xt, yt, xa, ya, xb, yb);
      if (0.000000 <= t1 && t1 <= 1.000000 && 0.000000 <= t2 &&
          t2 <= 1.000000) {
        tl[t1] = (o == 1 ? l : 1 - l);
      }
    }
    if (tl.size() > 1) {
      it = tl.begin();
      p = (*it).second;
      for (++it; it != tl.end(); ++it) {
        if ((*it).second != p) {
          ans++;
          p = (*it).second;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define N 100
#define INFF 100.0

double f(int x1, int y1, int x2, int y2, int X1, int Y1, int X2, int Y2) {
  if ((Y1 - Y2) * (x1 - x2) == (X1 - X2) * (y1 - y2))
    return INFF;
  return (double)((X1 - X2) * (y2 - Y2) - (Y1 - Y2) * (x2 - X2)) /
         (double)((Y1 - Y2) * (x1 - x2) - (X1 - X2) * (y1 - y2));
}

int main() {
  int nn, n, xa, ya, xb, yb, p, ans;
  int xs, ys, xt, yt, o, l;
  map<double, int> tl;
  double t1, t2;
  map<double, int>::iterator it;
  cin >> nn;
  for (int q = 0; q < nn; ++q) {
    cin >> xa >> ya >> xb >> yb;
    cin >> n;
    tl.clear();
    for (int i = 0; i < n; ++i) {
      cin >> xs >> ys >> xt >> yt >> o >> l;
      t1 = f(xa, ya, xb, yb, xs, ys, xt, yt);
      t2 = f(xs, ys, xt, yt, xa, ya, xb, yb);
      if (0.000000 <= t1 && t1 <= 1.000000 && 0.000000 <= t2 &&
          t2 <= 1.000000) {
        tl[t1] = (o == 1 ? l : 1 - l);
      }
    }
    it = tl.begin();
    p = (*it).second;
    ans = 0;
    for (++it; it != tl.end(); ++it) {
      if ((*it).second != p) {
        ans++;
        p = (*it).second;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, m, s, g1, g2, a, b, cost, mi;
  int map[101][101];
  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 < n + 1; i++) {
      for (int j = 0; j < n + 1; j++) {
        if (i == j)
          map[i][j] = 0;
        else
          map[i][j] = 1000000;
      }
    }
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> cost;
      map[a - 1][b - 1] = cost;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          map[j][k] = min(map[j][k], map[j][i] + map[i][k]);
        }
      }
    }
    mi = 1000000;
    for (int i = 0; i < n; i++)
      mi = min(mi, map[s - 1][i] + map[i][g1 - 1] + map[i][g2 - 1]);
    cout << mi << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m, s, g1, g2, a, b, cost;
  int map[100][100];
  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 < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          map[i][j] = 0;
        else
          map[i][j] = 10000000;
      }
    }
    for (int i = 0; i < 5; i++) {
      cin >> a >> b >> cost;
      map[a - 1][b - 1] = cost;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          map[i][j] = min(map[i][j], map[i][k] + map[k][j]);
        }
      }
    }
    int mi = 10000000;
    for (int i = 0; i < n; i++)
      mi = min(mi, map[s - 1][i] + map[i][g1 - 1] + map[i][g2 - 1]);
    cout << mi << endl;
    ;
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>

constexpr int MAX_N = 100, INF = (int)1e8;

int n;
int dp[MAX_N][MAX_N];

int main() {
  while (1) {
    int n, m, s, g[2];
    std::cin >> n >> m >> s >> g[0] >> g[1];
    if (n + m + s + g[0] + g[1] <= 0) {
      break;
    }
    --s;
    for (int i = 0; i < 2; ++i)
      --g[i];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
        dp[i][j] = INF;
    }
    for (int i = 0; i < n; ++i)
      dp[i][i] = 0;
    int a, b, c;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> b >> c;
      --a;
      --b;
      dp[a][b] = c;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k)
          dp[j][k] = std::min(dp[j][k], dp[j][i] + dp[i][k]);
      }
    }
    int ans = INF;
    for (int i = 0; i < n; ++i) {
      ans = std::min(ans, dp[s][i] + dp[i][g[0]] + dp[i][g[1]]);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

constexpr int MAX_N = 100, INF = (int)1e8;

int n;
int dp[MAX_N][MAX_N];

int main() {
  while (1) {
    int n, m, s, g[2];
    std::cin >> n >> m >> s >> g[0] >> g[1];
    --s;
    for (int i = 0; i < 2; ++i)
      --g[i];
    if (n + m + s + g[0] + g[1] == 0)
      break;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j)
        dp[i][j] = INF;
    }
    for (int i = 0; i < n; ++i)
      dp[i][i] = 0;
    int a, b, c;
    for (int i = 0; i < m; ++i) {
      std::cin >> a >> b >> c;
      --a;
      --b;
      dp[a][b] = c;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k)
          dp[j][k] = std::min(dp[j][k], dp[j][i] + dp[i][k]);
      }
    }
    int ans = INF;
    for (int i = 0; i < n; ++i) {
      ans = std::min(ans, dp[s][i] + dp[i][g[0]] + dp[i][g[1]]);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define INF (1e9)
#define N 101
using namespace std;
int n, m, s, g1, g2, b, e, c, d[N][N], ans;
void warshall_floyd();

int main() {
  while (1) {
    cin >> n >> m >> s >> g1 >> g2;
    if (!n && !m && !s && !g1 && !g2)
      break;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        d[i][j] = INF;
    for (int i = 0; i < N; i++)
      d[i][i] = 0;
    while (m--)
      cin >> b >> e >> c, d[b][e] = c;
    warshall_floyd();
    ans = INF;
    for (int i = 1; i <= n; i++) {
      if (d[s][i] == INF || d[i][g1] == INF || d[i][g2] == INF)
        continue;
      ans = min(ans, d[s][i] + d[i][g1] + d[i][g2]);
    }
    cout << ans << endl;
  }
  return 0;
}

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

Error: 0

Fixed submission:

#include <iostream>
#define N_MAX 105
#define INF (1e9)
using namespace std;
void prim();
void func(int);
int n, m, s, g1, g2, b1, b2, c, cost[N_MAX][N_MAX], mincost[N_MAX], ans;
bool used[N_MAX];

int main() {
  while (1) {
    cin >> n >> m >> s >> g1 >> g2;
    if (!n && !m && !s && !g1 && !g2)
      break;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++)
        cost[i][j] = INF;
    for (int i = 0; i < m; i++)
      cin >> b1 >> b2 >> c, cost[b1][b2] = cost[b2][b1] = c;
    prim();
  }
  return 0;
}

void prim() {
  for (int i = 1; i <= n; i++)
    mincost[i] = INF, used[i] = false;
  mincost[s] = 0;
  int res = 0;
  while (1) {
    int v = -1;
    for (int u = 1; u <= n; u++)
      if (!used[u] && (v == -1 || mincost[u] < mincost[v]))
        v = u;
    if (v == -1)
      break;
    used[v] = true;
    res += mincost[v];
    for (int u = 1; u <= n; u++)
      mincost[u] = min(mincost[u], cost[v][u]);
  }
  func(s);
  cout << ans << endl;
}

void func(int d) {
  if (d == g1 || d == g2)
    return;
  for (int i = 1; i <= n; i++) {
    if (mincost[i] == cost[d][i]) {
      ans += mincost[i];
      func(i);
    }
  }
}
Problem p01130 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m, s, g1, g2;
  while (true) {
    cin >> n >> m >> s >> g1 >> g2;
    if (n == 0)
      break;
    s--, g1--, g2--;
    const long long int INF = 1e10;
    vector<vector<long long int>> d(n, vector<long long int>(n, INF));
    for (int i = 0; i < m; i++) {
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--, b2--;
      d[b1][b2] = c;
    }
    for (int i = 0; i < n; i++)
      d[i][i] = 0;
    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]);
        }
      }
    }
    long long int res = 1e10;
    for (int g = 0; g < n; g++) {
      long long int share = d[s][g];
      long long int cost1 = d[g][g1];
      long long int cost2 = d[g][g2];
      long long int cost = share + cost1 + cost2;
      res = min(res, cost);
    }

    cout << res << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, m, s, g1, g2;
  while (cin >> n >> m >> s >> g1 >> g2, n) {
    s--, g1--, g2--;
    const long long int INF = 1e10;
    vector<vector<long long int>> d(n, vector<long long int>(n, INF));
    for (int i = 0; i < n; i++) {
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--, b2--;
      d[b1][b2] = c;
    }

    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]);
        }
      }
    }
    long long int res = 1e10;
    for (int g = 0; g < n; g++) {
      long long int share = d[s][g];
      long long int cost1 = d[g][g1];
      long long int cost2 = d[g][g2];
      long long int cost = share + cost1 + cost2;
      res = min(res, cost);
    }
    cout << res << endl;
  }

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

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

const int MAX = 101;
const int INF = (1 << 21);

int main() {
  int n, m;
  int s, g1, g2;
  int pipe[MAX][MAX];

  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;

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

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

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

Error: 0

Fixed submission:

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

const int MAX = 100;
const int INF = (1 << 10);

int main() {
  int n, m;
  int s, g1, g2;
  int pipe[MAX][MAX];

  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;

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

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

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