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

#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<double, double> PDD;
PDD calc(double mat[2][2], double vec[2]) {
  double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1];
  double c = vec[0], f = vec[1];
  double det = a * e - d * b;
  return make_pair((e * c - b * f) / det, (-c * d + a * f) / det);
}
int main() {
  int Tc;
  cin >> Tc;
  for (int tc = 0; tc < Tc; ++tc) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    if (y1 - y3 == 0) {
      swap(y2, y3);
      swap(x2, x3);
    } else if (y2 - y3 == 0) {
      swap(y1, y3);
      swap(x1, x3);
    }
    double A, B, C, D, E, F;
    A = (y1 + y3) / 2.;
    B = (x1 - x3) / (y1 - y3);
    C = (x1 + x3) / 2.;
    D = (y2 + y3) / 2.;
    E = (x2 - x3) / (y2 - y3);
    F = (x2 + x3) / 2.;
    double mat[2][2];
    mat[0][0] = B;
    mat[0][1] = 1;
    mat[1][0] = E;
    mat[1][1] = 1;
    double vec[2];
    vec[0] = A + B * C;
    vec[1] = D + E * F;
    PDD res = calc(mat, vec);
    double x = res.first, y = res.second;
    assert(x == x);
    assert(y == y);
    double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5);
    x = (double)(round(x * 1000)) / 1000.0;
    y = (double)(round(y * 1000)) / 1000.0;
    r = (double)(round(r * 1000)) / 1000.0;
    x = (x == -0.0) ? 0.0 : x;
    y = (y == -0.0) ? 0.0 : y;
    printf("%.3f %.3f %.3f\\n", x, y, r);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
typedef pair<double, double> PDD;
PDD calc(double mat[2][2], double vec[2]) {
  double a = mat[0][0], b = mat[0][1], d = mat[1][0], e = mat[1][1];
  double c = vec[0], f = vec[1];
  double det = a * e - d * b;
  return make_pair((e * c - b * f) / det, (-c * d + a * f) / det);
}
int main() {
  int Tc;
  cin >> Tc;
  for (int tc = 0; tc < Tc; ++tc) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double A, B, C, D, E, F;
    A = (y1 + y3) / 2.;
    B = (x1 - x3) / (y1 - y3);
    C = (x1 + x3) / 2.;
    D = (y2 + y3) / 2.;
    E = (x2 - x3) / (y2 - y3);
    F = (x2 + x3) / 2.;
    double mat[2][2];
    mat[0][0] = B;
    mat[0][1] = 1;
    mat[1][0] = E;
    mat[1][1] = 1;
    double vec[2];
    vec[0] = A + B * C;
    vec[1] = D + E * F;
    PDD res = calc(mat, vec);
    double x = res.first, y = res.second;
    assert(x == x);
    assert(y == y);
    double r = pow((x - x1) * (x - x1) + (y - y1) * (y - y1), 0.5);
    x = (double)(round(x * 1000)) / 1000.0;
    y = (double)(round(y * 1000)) / 1000.0;
    r = (double)(round(r * 1000)) / 1000.0;
    x = (x == -0.0) ? 0.0 : x;
    y = (y == -0.0) ? 0.0 : y;
    printf("%.3f %.3f %.3f\\n", x, y, r);
  }
  return 0;
}
Problem p00010 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iomanip>
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  double rax, ray, rbx, rby, rcx, rcy;
  for (int i = 0; i < n; i++) {
    double ax, ay, bx, by, cx, cy, aa, bb, cc, a, b, c, d, e, f, rx, ry, rr;
    std::cin >> rax >> ray >> rbx >> rby >> rcx >> rcy;
    ax = rbx - rax;
    ay = rby - ray;
    bx = rcx - rbx;
    by = rcy - rby;
    cx = rax - rcx;
    cy = ray - rcy;
    aa = ax * ax + ay * ay;
    bb = bx * bx + by * by;
    cc = cx * cx + cy * cy;
    a = std::sqrt(aa);
    b = std::sqrt(bb);
    c = std::sqrt(cc);
    d = aa * (bb + cc - aa);
    e = bb * (cc + aa - bb);
    f = cc * (aa + bb - cc);
    rx = ((d * rcx) + (e * rax) + (f * rbx)) / (d + e + f);
    ry = ((d * rcy) + (e * ray) + (f * rby)) / (d + e + f);
    rr = (a * b * c) /
         std::sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c));
    std::cout << std::fixed;
    std::cout << std::setprecision(3) << rx << " " << ry << " " << rr
              << std::endl;
  }

  return 0;
}

Error: 0
2 0 -2
4 4 8
2 2 2.82843
32 32 0


Fixed submission:

#include <cmath>
#include <iomanip>
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  double rax, ray, rbx, rby, rcx, rcy;
  for (int i = 0; i < n; i++) {
    double ax, ay, bx, by, cx, cy, aa, bb, cc, a, b, c, d, e, f, rx, ry, rr;
    std::cin >> rax >> ray >> rbx >> rby >> rcx >> rcy;
    ax = rbx - rax;
    ay = rby - ray;
    bx = rcx - rbx;
    by = rcy - rby;
    cx = rax - rcx;
    cy = ray - rcy;
    std::cerr << ax << " " << bx << " " << cx << std::endl;
    aa = ax * ax + ay * ay;
    bb = bx * bx + by * by;
    cc = cx * cx + cy * cy;
    std::cerr << aa << " " << bb << " " << cc << std::endl;
    a = std::sqrt(aa);
    b = std::sqrt(bb);
    c = std::sqrt(cc);
    std::cerr << a << " " << b << " " << c << std::endl;
    d = aa * (bb + cc - aa);
    e = bb * (cc + aa - bb);
    f = cc * (aa + bb - cc);
    std::cerr << d << " " << e << " " << f << std::endl;
    rx = ((d * rcx) + (e * rax) + (f * rbx)) / (d + e + f);
    ry = ((d * rcy) + (e * ray) + (f * rby)) / (d + e + f);
    rr = (a * b * c) /
         std::sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c));
    std::cout << std::fixed;
    std::cout << std::setprecision(3) << rx << " " << ry << " " << rr
              << std::endl;
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  double a, b, c, d, e, f;
  double x1, x2, x3, y1, y2, y3, px, py, r;
  cin >> n;
  while (n--) {
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    a = 2 * (x1 - x2);
    b = 2 * (y1 - y2);
    c = x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2;
    d = 2 * (x1 - x3);
    e = 2 * (y1 - y3);
    f = x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3;
    px = (c * e - b * f) / (a * e - b * d);
    py = (c * d - a * f) / (b * d - a * e);
    r = sqrt((px - x1) * (px - x1) + (py - y1) * (py - y1));
    printf("%.3f %.3f %.3f\\n", px, py, r);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n, a, b, c, d, e, f;
  double x1, x2, x3, y1, y2, y3, px, py, r;
  cin >> n;
  while (n--) {
    cin >> x1 >> x2 >> x3 >> y1 >> y2 >> y3;
    a = 2 * (x1 - x2);
    b = 2 * (y1 - y2);
    c = x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2;
    d = 2 * (x1 - x3);
    e = 2 * (y1 - y3);
    f = x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3;
    px = (c * e - b * f) / (a * e - b * d);
    py = (c * d - a * f) / (b * d - a * e);
    r = sqrt(pow(px - x1, 2) + pow(py - y1, 2));
    printf("%.3f %.3f %.3f\\n", px, py, r);
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  int n;
  float x[3], y[3], a, b, c, d, X, Y, px, py;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++)
      cin >> x[j] >> y[j];

    a = x[0] - x[1];
    b = y[0] - y[1];
    c = x[0] - x[2];
    d = y[0] - y[2];
    X = pow(x[0], 2) - pow(x[1], 2) + pow(y[0], 2) - pow(y[1], 2);
    Y = pow(x[0], 2) - pow(x[2], 2) + pow(y[0], 2) - pow(y[2], 2);
    px = (d * X - b * Y) / (a * d - b * c) / 2;
    py = (-c * X + a * Y) / (a * d - b * c) / 2;

    printf("%.3f %.3f %.3f\\n", px, py,
           sqrt(pow(x[0] - px, 2) + pow(y[0] - py, 2)));
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  int val;
  while (cin >> val)
    cerr << val << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

#define inOut(a, b)                                                            \\
  freopen(a, "r", stdin);                                                      \\
  freopen(b, "w", stdout);
#define RESET(a) memset(a, 0, sizeof(a))
#define MEMO(a) memset(a, -1, sizeof(a))
#define DEBUG puts("Debug-Has-Come-Until-Here")

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  cin.tie(NULL);

  double x1, x2, x3, y1, y2, y3;
  double a, b, c, d, e, f;
  double x, y;
  int dummy;

  scanf("%d", &dummy);
  while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3) !=
         EOF) {
    a = -2 * x1 + 2 * x2;
    b = -2 * y1 + 2 * y2;
    c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1);
    d = -2 * x2 + 2 * x3;
    e = -2 * y2 + 2 * y3;
    f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2);

    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - e * a);
    printf("%.3lf %.3lf %.3lf\\n", x, y,
           sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back

#define inOut(a, b)                                                            \\
  freopen(a, "r", stdin);                                                      \\
  freopen(b, "w", stdout);
#define RESET(a) memset(a, 0, sizeof(a))
#define MEMO(a) memset(a, -1, sizeof(a))
#define DEBUG puts("Debug-Has-Come-Until-Here")

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  cin.tie(NULL);

  double x1, x2, x3, y1, y2, y3;
  double a, b, c, d, e, f;
  double x, y;
  int dummy;

  scanf("%d", &dummy);
  while (scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3)) {
    a = -2 * x1 + 2 * x2;
    b = -2 * y1 + 2 * y2;
    c = (x2 * x2 - x1 * x1) + (y2 * y2 - y1 * y1);
    d = -2 * x2 + 2 * x3;
    e = -2 * y2 + 2 * y3;
    f = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2);

    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - e * a);
    printf("%.3lf %.3lf %.3lf\\n", x, y,
           sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)));
  }

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

#include <math.h>
#include <stdio.h>

int main(void) {
  float x1, x2, x3, y1, y2, y3;
  float xp, yp, r;
  float rs;
  int n;

  scanf("%d", &n);

  while (n) {
    scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);

    xp = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
          (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
         (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
    yp = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
          (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) /
         (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
    r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp));

    n--;

    printf("%.3f %.3f %.3f\\n", xp, yp, r);
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int main(void) {
  float x1, x2, x3, y1, y2, y3;
  float xp, yp, r;
  float rs;
  int n;

  scanf("%d", &n);

  while (n) {
    scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);

    yp = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) -
          (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) /
         (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
    xp = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) -
          (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) /
         (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
    r = sqrt((x1 - xp) * (x1 - xp) + (y1 - yp) * (y1 - yp));

    printf("%.3f %.3f %.3f\\n", xp, yp, r);
  }

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

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

const double EPS = 1e-3;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {
  int n, p, q;
  double x[3], y[3], ta, tb, tc, sta, cta, r;
  double z[2], a, b, c, d, e, f;
  bool zf;
  cin >> n;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < 3; i++) {
      cin >> x[i] >> y[i];
    }
    ta = dist(x[1], y[1], x[2], y[2]);
    tb = dist(x[0], y[0], x[1], y[1]);
    tc = dist(x[0], y[0], x[2], y[2]);
    cta = (ta * ta - tb * tb - tc * tc) / (2 * tb * tc);
    sta = sqrt(1 - cta * cta);
    r = ta / sta / 2;

    double m[2][3] = {{2 * (x[0] - x[1]), 2 * (y[0] - y[1]),
                       x[0] * x[0] + y[0] * y[0] - x[1] * x[1] - y[1] * y[1]},
                      {2 * (x[0] - x[2]), 2 * (y[0] - y[2]),
                       x[0] * x[0] + y[0] * y[0] - x[2] * x[2] - y[2] * y[2]}};
    zf = false;
    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        if (m[i][j] == 0) {
          p = i;
          q = j;
          zf = true;
        }
      }
    }
    if (zf) {
      z[1 - q] = m[p][2] / m[p][1 - q];
      z[q] = (m[1 - p][2] - m[1 - p][1 - q] * z[1 - q]) / m[1 - p][q];
    } else {
      a = m[0][0];
      b = m[0][1];
      c = m[0][2];
      d = m[1][0];
      e = m[1][1];
      f = m[1][2];
      z[1] = (f - d * c / a) / (e - d * b / a);
      z[0] = (c - b * z[1]) / a;
    }
    printf("%.3f %.3f %.3f\\n", z[0], z[1], r);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

const double EPS = 1e-5;

double dist(double x1, double y1, double x2, double y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {
  int n;
  double x[3], y[3], a, b, c, sa, ca;
  double px, py, r;
  cin >> n;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < 3; i++) {
      cin >> x[i] >> y[i];
    }
    a = dist(x[1], y[1], x[2], y[2]);
    b = dist(x[0], y[0], x[1], y[1]);
    c = dist(x[0], y[0], x[2], y[2]);
    ca = (a * a - b * b - c * c) / (2 * b * c);
    sa = sqrt(1 - ca * ca);
    r = a / sa / 2;

    for (px = -r; px <= r; px += 0.000001) {
      py = sqrt(r * r - px * px);
      if (abs(pow(px - x[0], 2) + pow(py - y[0], 2) - r * r) < EPS &&
          abs(pow(px - x[1], 2) + pow(py - y[1], 2) - r * r) < EPS &&
          abs(pow(px - x[2], 2) + pow(py - y[2], 2) - r * r) < EPS) {
        break;
      }
    }
    printf("%.3f %.3f %.3f\\n", px, py, r);
  }
  return 0;
}
Problem p00010 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <complex>
#include <stdio.h>
#define F(a, b, c) acos((b * b + c * c - a * a) / 2 / b / c)
int main() {
  int n;
  double d, e, f, g, h, i;
  for (scanf("%d", &n); n--;) {
    scanf("%lf%lf%lf%lf%lf%lf", &d, &g, &e, &h, &f, &i);
    std::complex<double> a(d, g), b(e, h), c(f, i);
    double A = abs(b - c), B = abs(c - a), C = abs(a - b),
           s = sin(2 * F(A, B, C)), t = sin(2 * F(B, C, A)),
           u = sin(2 * F(C, A, B)), v = s + t + u;
    printf("%.3f %.3f %.3f\\n", (d * s + e * t + f * u) / v,
           (g * s + h * t + i * u) / v, A / sin(F(A, B, C)) / 2);
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <complex>
#include <cstdio>
using namespace std;
typedef complex<double> P;
#define F(a, b, c) acos((b * b + c * c - a * a) / 2 / b / c)
int main() {
  double n, d, e, f, g, h, i;
  for (scanf("%d", &n); n--;) {
    scanf("%lf%lf%lf%lf%lf%lf", &d, &g, &e, &h, &f, &i);
    P a(d, g), b(e, h), c(f, i);
    double A = abs(b - c), B = abs(c - a), C = abs(a - b),
           s = sin(2 * F(A, B, C)), t = sin(2 * F(B, C, A)),
           u = sin(2 * F(C, A, B)), v = s + t + u;
    printf("%.3f %.3f %.3f\\n", (d * s + e * t + f * u) / v,
           (g * s + h * t + i * u) / v, A / sin(F(A, B, C)) / 2);
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

// 0011
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int w, h;
  char dummy;
  std::cin >> w >> h;
  std::vector<int> vec(w);
  for (int i = 0; i < w; ++i)
    vec[i] = i + 1;
  for (int i = 0; i < h; i++) {
    int a, b;
    std::cin >> a >> dummy >> b;
    {
      using std::swap;
      swap(vec[a - 1], vec[b - 1]);
    }
  }
  for (int i = 0; i < w; i++) {
    std::cout << vec[i] << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
int main() {
  int w, h;
  std::cin >> w >> h;
  std::vector<int> vec(w);
  for (int i = 0; i < w; ++i)
    vec[i] = i + 1;
  for (int i = 0; i < h; i++) {
    std::string str;
    std::cin >> str;
    {
      char c = str[0], d = str[2];
      int a = c - '0' - 1, b = d - '0' - 1;
      int n = vec[a];
      vec[a] = vec[b];
      vec[b] = n;
    }
  }
  for (int i = 0; i < w; i++) {
    std::cout << vec[i] << std::endl;
  }
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int w, n, x, y;
  string str;
  cin >> w >> n;
  int a[31];
  for (int i = 0; i <= w; i++) {
    a[i] = i;
  } // 1 = 49
  for (int i = 0; i < n; i++) {
    cin >> str;
    x = stoi(str);
    if (to_string(x).size() == 1 && str.size() == 3) {
      int temp = str[2];
      y = temp - 48;
    } else if (to_string(x).size() == 2 && str.size() == 4) {
      int temp = str[3];
      y = temp - 48;
    } else if (to_string(x).size() == 1 && str.size() == 4) {
      int juunokurai = str[2];
      int itinokurai = str[3];
      y = (juunokurai - 48) * 10 + (itinokurai - 48);
    } else {
      int juunokurai = str[3];
      int itinokurai = str[4];
      y = (juunokurai - 48) * 10 + (itinokurai - 48);
    }
    int tmp = a[x];
    a[x] = a[y];
    a[y] = tmp;
  }
  for (int i = 1; i <= w; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int w, n, x, y;
  string str;
  cin >> w >> n;
  int a[31];
  for (int i = 0; i <= w; i++) {
    a[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> str;
    x = str[0];
    y = str[2];
    int tmp = a[x - 48];
    a[x - 48] = a[y - 48];
    a[y - 48] = tmp;
  }
  for (int i = 1; i <= w; i++) {
    cout << a[i] << endl;
  }
  return 0;
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int w, n;
  int a[30] = {-1};
  int j, k;
  int temp1;

  while (cin >> w) {

    if (w == 0)
      break;

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

    cin >> n;

    for (int i = 0; i < n; i++) {
      char temp;

      cin >> j >> temp >> k;

      temp1 = a[j - 1];
      a[j - 1] = a[k - 1];
      a[k - 1] = temp1;
    }

    for (int i = 0; i < w; i++) {
      cout << a[i] << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int w, n;
  int a[30] = {-1};
  int j, k;
  int temp, temp1;

  while (cin >> w) {

    if (w == 0)
      break;

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

    cin >> n;

    for (int i = 0; i < n; i++) {

      cin >> j >> temp >> k;

      temp1 = a[j - 1];
      a[j - 1] = a[k - 1];
      a[k - 1] = temp1;
    }

    for (int i = 0; i < w; i++) {
      cout << a[i] << endl;
    }
  }

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

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int str[30];
  int w, n, i;
  int a, b;
  int t;

  cin >> w;
  cin >> n;

  for (i = 0; i < 30; i++) {
    str[i] = i + 1;
  }

  for (i = 0; i < n; i++) {
    scanf("%d,%d", &a, &b);

    t = str[a - 1];
    str[a - 1] = str[b - 1];
    str[b - 1] = t;
  }
  for (i = 0; i < w; i++) {
    cout << str[i] << "\\n";
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int w, n;
  int a[30], b[30];
  int p, q, r;
  int base[31];

  base[0] = 0;
  w = 0;
  n = 0;

  cin >> w;
  cin >> n;

  for (int i = 0; i <= w; i++) {
    base[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < n; i++) {
    p = a[i];
    q = b[i];
    r = base[p];
    base[p] = base[q];
    base[q] = r;
  }

  for (int i = 1; i <= w; i++) {
    cout << base[i];
    if (i != w) {
      cout << " ";
    }
    if (i == w) {
      cout << "\\n";
    }
  }

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

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int w, n;
  int d[31];
  while (cin >> w >> n) {
    for (int i = 1; i <= w; i++)
      d[i] = i;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < s.size(); j++)
        if (s[j] == ',')
          s[j] = ' ';
      istringstream iss(s);
      int a, b;
      iss >> a >> b;
      swap(d[a], d[b]);
    }
    for (int i = 1; i <= w; i++)
      cout << d[i] << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int w, n;
  int d[31];
  while (cin >> w >> n) {
    for (int i = 1; i <= w; i++)
      d[i] = i;
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      istringstream iss(s);
      for (int j = 0; j < s.size(); j++)
        if (s[j] == ',')
          s[j] = ' ';
      int a, b;
      iss >> a >> b;
      swap(d[a], d[b]);
    }
    for (int i = 1; i <= w; i++)
      cout << d[i] << endl;
  }
}
Problem p00011 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int w, n;
  cin >> w;
  cin >> n;

  vector<int> s(w + 1);
  for (int i = 1; i <= w; ++i)
    s[i] = i;

  while (n--) {
    int a, b;
    scanf("%d,%d", &a, &b);

    swap(s[a], s[b]);
  }

  for (int i = 1; i <= w; ++i)
    cout << s[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int w, n;
  cin >> w;
  cin >> n;

  vector<int> s(w);
  for (int i = 1; i <= w; ++i)
    s[i] = i;

  while (n--) {
    int a, b;
    scanf("%d,%d", &a, &b);

    swap(s[a], s[b]);
  }

  for (int i = 1; i <= w; ++i)
    cout << s[i] << endl;

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

#include <iostream>

using namespace std;

int main() {
  int w, n;
  cin >> w >> n;
  int s[w];

  for (int i = 0; i < w; i++) {
    s[i] = i + 1;
  }

  for (int t = 0; t < n; t++) {
    int a, b;
    char c;
    cin >> a >> c >> b;
    swap(s[a - 1], s[b - 1]);
  }

  for (int i = 0; i < w; i++) {
    cout << s[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int w, n;
  cin >> w >> n;
  int s[w];

  for (int i = 0; i < w; i++) {
    s[i] = i + 1;
    while (n--) {
      int a, b, c;
      cin >> a >> b;

      int tmp = s[a - 1];
      s[a - 1] = s[b - 1];
      s[b - 1] = tmp;
    }

    for (int i = 0; i < w; i++) {
      cout << s[i];
    }
    cout << endl;
  }
}