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

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

struct pq {
  int p;
  int q;
};

int main() {
  int n, m, a;
  while (cin >> n >> m >> a, n | m | a) {
    int *tate = new int[n];
    for (int i = 0; i < n; ++i) {
      tate[i] = i + 1;
    }
    multimap<int, pq> yoko;
    for (int i = 0; i < m; ++i) {
      int h;
      pq tmp;
      cin >> h >> tmp.p >> tmp.q;
      yoko.insert(make_pair(h, tmp));
    }
    multimap<int, pq>::iterator it;
    for (it = yoko.begin(); it != yoko.end(); ++it) {
      pq tmp = (*it).second;
      swap(tate[tmp.p - 1], tate[tmp.q - 1]);
    }
    cout << tate[a - 1] << endl;
    yoko.clear();
    delete[] tate;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m, a;
  while (cin >> n >> m >> a, n | m | a) {
    int *tate = new int[n];
    for (int i = 0; i < n; ++i) {
      tate[i] = i + 1;
    }
    for (int i = 0; i < m; ++i) {
      int h, p, q;
      cin >> h >> p >> q;
      swap(tate[p], tate[q]);
    }
    cout << tate[a + 1] << endl;
    delete[] tate;
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>

using namespace std;
int n, m, a;

void solve() {
  int ary[1003];
  for (int i = 0; i <= n; i++)
    ary[i] = i;
  pair<int, pair<int, int>> amida[1003];
  for (int i = 0; i < m; i++) {
    int h, p, q;
    cin >> h >> p >> q;
    amida[i] = (make_pair(h, pair<int, int>(p, q)));
  }

  sort(amida, amida + m);
  for (int i = 0; i < m; i++) {
    swap(ary[amida[i].second.first], ary[amida[i].second.second]);
  }
  cout << ary[a] << endl;
}

int main() {
  while (cin >> n >> m >> a) {
    if (n + m + a == 0)
      return 0;
    solve();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(itr, data)                                                         \\
  for (__typeof((data).begin()) itr = (data).begin(); itr != (data).end();     \\
       ++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

typedef pair<int, int> P;

int ary[105];

int main() {
  rep(i, 105) ary[i] = i + 1;
  int n, m, a;
  int h, p, q;
  cin >> n >> m >> a;

  while (cin >> h >> p >> q) {
    if (h + p + q == 0)
      break;
    swap(ary[p], ary[q]);
  }

  rep(i, n + 1) {
    if (ary[i] == a) {
      cout << n - i << endl;
      return 0;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <utility>
// #include <functional>
// #include <boost/foreach.hpp>
using namespace std;

int main() {
  pair<int, pair<int, int>> pai[1001];
  int n, m, a, t, y1, y2;
  while (1) {
    cin >> n >> m >> a;
    if (n == 0)
      break;
    for (int i = 0; i < m; i++) { // 横棒の数だけ
      cin >> t >> y1 >> y2;
      pai[i].first = t;
      pai[i].second.first = y1;
      pai[i].second.second = y2;
    }
    sort(pai, pai + m);
    reverse(pai, pai + m);
    for (int i = 0; i < m; i++) {
      if (pai[i].second.first == a)
        a = pai[i].second.second;
      else if (pai[i].second.second == a)
        a = pai[i].second.first;
    }
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int me, i, b[100][3], max = 0, n, m;
  while (1) {
    scanf("%d %d %d", &m, &n, &me);
    if (m == 0 && n == 0 && me == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &b[i][0], &b[i][1], &b[i][2]);
      if (b[i][0] > max)
        max = b[i][0];
    }
    i--;

    while (1) {
      if (b[i][0] == max) {
        if (b[i][1] == me) {
          me = b[i][2];
          i = n;
          max--;
        } else if (b[i][2] == me) {
          me = b[i][1];
          i = n;
          max--;
        }
      }
      i--;
      if (i == -1) {
        i = n - 1;
        max--;
      }
      if (max == 0)
        break;
    }
    printf("%d\\n", me);
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for (typeof(n) i = (a); i < (n); i++)

pair<int, pair<int, int>> dat[1000];

int main() {
  int n, m, a;
  while (scanf("%d%d%d", &n, &m, &a), n + m + a) {
    rep(i, m) {
      int h, p, q;
      scanf("%d%d%d", &h, &p, &q);
      dat[i] = make_pair(-h, make_pair(p, q));
    }
    sort(dat, dat + m);
    rep(i, m) {
      if (a == dat[i].second.first) {
        a = dat[i].second.second;
      } else if (a == dat[i].second.second) {
        a = dat[i].second.first;
      }
    }
    printf("%d\\n", a);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for (int i = (a); i < (n); i++)

int H;
map<int, map<int, int>> mp;

int search(int a, int h) {
  for (auto iter = mp[a].begin(); iter != mp[a].end(); iter++) {
    if (iter->first <= h) {
      h = iter->first;
      break;
    }
  }

  if (h == 1)
    return mp[a][h];
  return search(mp[a][h], h);
}

int main() {
  while (1) {
    int n, m, a;
    cin >> n >> m >> a;
    if (n == 0 && m == 0 && a == 0)
      break;

    mp.clear();
    H = -1;
    rep(_, m) {
      int h, p, q;
      cin >> h >> p >> q;
      mp[p][h] = q;
      mp[q][h] = p;
      H = max(H, h);
    }
    cout << search(a, H) << endl;
  }
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int amd[1010][1010];

int main() {
  while (1) {
    int n, m, a;
    cin >> n >> m >> a;
    if (!n && !m && !a)
      break;
    memset(amd, 0, sizeof(amd));
    int d = 0;
    rep(i, 0, m) {
      int h, p, q;
      cin >> h >> p >> q;
      if (p > q)
        swap(p, q);
      amd[h][p] = 1;
      amd[h][q] = 2;
      d = max(d, h);
    }
    while (d) {
      // printf("n=%d a=%d amd[n][a]=%d\\n",n,a,amd[n][a]);
      if (amd[d][a] == 1)
        a++;
      else if (amd[d][a] == 2)
        a--;
      d--;
    }
    cout << a << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define all(a) a.begin(), a.end()
#define len(x) ((int)(x).size())
#define tmax(a, b, c) max((a), max((b), (c)))
#define tmin(a, b, c) min((a), min((b), (c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<vector<int>> VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int amd[110][1010];

int main() {
  while (1) {
    int n, m, a;
    cin >> n >> m >> a;
    if (!n && !m && !a)
      break;
    memset(amd, 0, sizeof(amd));
    int d = 0;
    rep(i, 0, m) {
      int h, p, q;
      cin >> h >> p >> q;
      if (p > q)
        swap(p, q);
      amd[h][p] = 1;
      amd[h][q] = 2;
      d = max(d, h);
    }
    while (d) {
      // printf("n=%d a=%d amd[n][a]=%d\\n",n,a,amd[n][a]);
      if (amd[d][a] == 1)
        a++;
      else if (amd[d][a] == 2)
        a--;
      d--;
    }
    cout << a << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> tri;
int main() {
  int n, m, a;
  vector<tri> line;
  while (cin >> n >> m >> a) {
    if (n == 0)
      break;
    int h, p, q;
    for (int i = 0; i < m; i++) {
      cin >> h >> p >> q;
      line.push_back(tri(h, pii(p, q)));
    }
    sort(line.begin(), line.end(), greater<tri>());
    int cnt = 0;
    for (int i = line[0].first; i > 0 && cnt < line.size();) {
      if (line[cnt].first <= i) {
        if (line[cnt].second.first == a) {
          // cout << a << endl;
          a = line[cnt].second.second;
          i = line[cnt].first - 1;
        } else if (line[cnt].second.second == a) {
          a = line[cnt].second.first;
          i = line[cnt].first - 1;
        }
      }
      cnt++;
    }
    cout << a << endl;
    line.clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> tri;
int main() {
  int n, m, a;
  vector<tri> line;
  while (cin >> n >> m >> a) {
    if (n == 0)
      break;
    int h, p, q;
    for (int i = 0; i < m; i++) {
      cin >> h >> p >> q;
      line.push_back(tri(h, pii(p, q)));
    }
    sort(line.begin(), line.end(), greater<tri>());
    int cnt = 0;
    for (int i = line[0].first; i > 0 && cnt < line.size();) {
      if (line[cnt].first < i)
        break;
      if (line[cnt].first == i) {
        if (line[cnt].second.first == a) {
          // cout << a << endl;
          a = line[cnt].second.second;
          i--;
        } else if (line[cnt].second.second == a) {
          a = line[cnt].second.first;
          i--;
        }
        cnt++;
      }
    }
    cout << a << endl;
    line.clear();
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, m, a;

  while (1) {
    cin >> n >> m >> a;

    vector<vector<int>> line;
    int s1, s2, s3;
    int now;

    if (n == 0 && m == 0 && a == 0)
      break;

    line = vector<vector<int>>(n + 5000, vector<int>(n + 5000, 0));

    for (int i = 0; i < m; ++i) {
      cin >> s1 >> s2 >> s3;

      line[s1][s2] = s3;
      line[s1][s3] = s2;
    }

    now = a;

    for (int i = 5000; i >= 1; --i) {
      if (line[i][now] != 0) {
        now = line[i][now];
      }
    }
    cout << now << endl;
  }

  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  int n, m, a;

  while (1) {
    cin >> n >> m >> a;

    vector<vector<int>> line;
    int s1, s2, s3;
    int now;

    if (n == 0 && m == 0 && a == 0)
      break;

    line = vector<vector<int>>(n + 10000, vector<int>(n + 10000, 0));

    for (int i = 0; i < m; ++i) {
      cin >> s1 >> s2 >> s3;

      line[s1][s2] = s3;
      line[s1][s3] = s2;
    }

    now = a;

    for (int i = n; i >= 1; --i) {
      if (line[i][now] != 0) {
        now = line[i][now];
      }
    }
    cout << now << endl;
  }

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

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

int main(int argc, char *argv[]) {
  int n, m, a, h, p, q;
  vector<vector<pair<int, int>>> amida(1001);
  vector<pair<int, int>>::iterator itr;
  while (cin >> n >> m >> a, n) {
    for (int i = 0; i < m; ++i) {
      cin >> h >> p >> q;
      amida[h].push_back(make_pair(p, q));
    }
    for (int i = 1000; i > 0; --i) {
      itr = amida[i].begin();
      while (itr != amida[i].end()) {
        if (itr->first == a) {
          a = itr->second;
          break;
        } else if (itr->second == a) {
          a = itr->first;
          break;
        }
        itr++;
      }
    }
    cout << a << endl;
    for (int i = 0; i < 1001; ++i) {
      amida[i].clear();
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main(int argc, char *argv[]) {
  int n, m, a, h, p, q;
  while (cin >> n >> m >> a, n) {
    vector<vector<pair<int, int>>> amida(m + 1);
    vector<pair<int, int>>::iterator itr;
    for (int i = 0; i < m; ++i) {
      cin >> h >> p >> q;
      amida[h].push_back(make_pair(p, q));
    }
    for (int i = m; i > 0; --i) {
      itr = amida[i].begin();
      while (itr != amida[i].end()) {
        if (itr->first == a) {
          a = itr->second;
          break;
        } else if (itr->second == a) {
          a = itr->first;
          break;
        }
        itr++;
      }
    }
    cout << a << endl;
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long

vector<vector<int>> w_line;

signed main() {
  int n, m, a;
  while (cin >> n >> m >> a, n) {
    int w_line[1001][101] = {0};
    for (int i = 0; i < m; i++) {
      int h, p, q;
      cin >> h >> p >> q;
      w_line[h][p] = q;
      w_line[h][q] = p;
    }

    for (int i = 1000; i >= 1; i--) {
      if (w_line[i][a])
        a = w_line[i][a];
    }

    cout << a << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

#define int long long

vector<vector<int>> w_line;

signed main() {
  int n, m, a;
  while (cin >> n >> m >> a, n) {
    map<int, int> w_line[1001];
    for (int i = 0; i < n; i++) {
      int h, p, q;
      cin >> h >> p >> q;
      w_line[h][p] = q;
      w_line[h][q] = p;
    }

    for (int i = 1000; i >= 1; i--) {
      if (w_line[i][a])
        a = w_line[i][a];
    }

    cout << a << endl;
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
#define max(a, b) a > b ? a : b

int main(void) {
  int n, m, a, h, p, q, flag[1000][100], i, j, k, mx;
  while (1) {
    scanf("%d%d%d", &n, &m, &a);
    if (n == 0 && m == 0 && a == 0)
      break;
    memset(flag, -1, sizeof(flag));
    mx = -1;
    a--;
    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &h, &p, &q);
      flag[h - 1][p - 1] = q - 1;
      flag[h - 1][q - 1] = p - 1;
      mx = max(mx, h - 1);
    }
    for (i = mx; i >= 0; i--) {
      for (j = 0; j < n; j++) {
        if (flag[i][a] != -1) {
          a = flag[i][a];
          break;
        }
      }
    }
    printf("%d\\n", a + 1);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
#define max(a, b) a > b ? a : b

int main(void) {
  int n, m, a, h, p, q, flag[1000][100][100], i, j, k, mx;
  while (1) {
    scanf("%d%d%d", &n, &m, &a);
    if (n == 0 && m == 0 && a == 0)
      break;
    for (i = 0; i < 1000; i++) {
      for (j = 0; j < n; j++) {
        for (k = 0; k < n; k++)
          flag[i][j][k] = 0;
      }
    }

    mx = -1;
    a--;
    for (i = 0; i < m; i++) {
      scanf("%d%d%d", &h, &p, &q);
      flag[h - 1][p - 1][q - 1] = 1;
      flag[h - 1][q - 1][p - 1] = 1;
      mx = max(mx, h - 1);
    }
    for (i = mx; i >= 0; i--) {
      for (j = 0; j < n; j++) {
        if (flag[i][a][j]) {
          a = j;
          break;
        }
      }
    }
    printf("%d\\n", a + 1);
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<double, double> P;
int b[19][19];

int main() {

  int n, m, a;
  while (cin >> n >> m >> a, n != 0 || m != 0 || a != 0) {
    vector<vector<int>> kuji(1020, vector<int>(2 * n + 10));
    int h, p, q;
    for (int i = 0; i < m; i++) {
      cin >> h >> p >> q;
      kuji[h][2 * max(p, q) - 2] = 1;
    }
    int now = 2 * a - 1;
    for (int i = 1000; i >= 0; i--) {
      if (kuji[i][now - 1])
        now -= 2;
      else if (kuji[i][now + 1])
        now += 2;
    }
    cout << now / 2 + 1 << endl;
  }
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<double, double> P;
int b[19][19];

int main() {

  int n, m, a;
  while (cin >> n >> m >> a, n != 0 || m != 0 || a != 0) {
    vector<vector<int>> kuji(n + 100, vector<int>(2 * m + 100));
    int h, p, q;
    for (int i = 0; i < m; i++) {
      cin >> h >> p >> q;
      kuji[h][2 * max(p, q) - 2] = 1;
    }
    int now = 2 * a - 1;
    for (int i = n - 1; i >= 0; i--) {
      if (kuji[i][now - 1] == 1)
        now -= 2;
      else if (kuji[i][now + 1] == 1)
        now += 2;
    }
    cout << now / 2 + 1 << endl;
  }
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

struct ans {
  int n;
  ans *next;
};

int main() {
  //
  ans *start = new ans();
  start->next = NULL;
  ans *end = start, *buf;
  //
  char s[20];
  char *ps;
  int i, j;
  int n, m, a;
  int h, p, q;
  int line[100][1000];
  int x, y;
  while (fgets(s, sizeof(s), stdin)) {
    ps = strtok(s, " ");
    n = atoi(ps);
    ps = strtok(NULL, " ");
    m = atoi(ps);
    ps = strtok(NULL, " ");
    a = atoi(ps) - 1;
    if (n == 0 && m == 0 && a == -1)
      break;
    memset(line, 0, sizeof(line));
    for (i = 0; i < m; i++) {
      fgets(s, sizeof(s), stdin);
      ps = strtok(s, " ");
      h = atoi(ps) - 1;
      ps = strtok(NULL, " ");
      p = atoi(ps) - 1;
      ps = strtok(NULL, " ");
      q = atoi(ps) - 1;

      line[p][h] = (q - p);
      line[q][h] = (p - q);
    }
    x = a;
    for (y = 999; y >= 0; y--)
      x += line[x][y];
    //
    buf = new ans();
    buf->n = x + 1;
    buf->next = NULL;
    end->next = buf;
    end = buf;
    //
  }
  buf = start->next;
  delete start;
  while (buf != NULL) {
    cout << (buf->n) << endl;
    end = buf;
    buf = buf->next;
    delete end;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

struct ans {
  int n;
  ans *next;
};

int main() {
  //
  ans *start = new ans();
  start->next = NULL;
  ans *end = start, *buf;
  //
  char s[20];
  char *ps;
  int i, j;
  int n, m, a;
  int h, p, q;
  int line[100][1000];
  int x, y;
  while (fgets(s, sizeof(s), stdin)) {
    ps = strtok(s, " ");
    n = atoi(ps);
    ps = strtok(NULL, " ");
    m = atoi(ps);
    ps = strtok(NULL, " ");
    a = atoi(ps) - 1;
    if (n == 0 && m == 0 && a == -1)
      break;
    memset(line, 0, sizeof(line));
    for (i = 0; i < m; i++) {
      fgets(s, sizeof(s), stdin);
      ps = strtok(s, " ");
      h = atoi(ps) - 1;
      ps = strtok(NULL, " ");
      p = atoi(ps) - 1;
      ps = strtok(NULL, " ");
      q = atoi(ps) - 1;

      line[p][h] = (p - q);
      line[q][h] = (q - p);
    }
    x = a;
    for (y = 999; y >= 0; y--)
      x += line[x][y];
    //
    buf = new ans();
    buf->n = x + 1;
    buf->next = NULL;
    end->next = buf;
    end = buf;
    //
  }
  buf = start->next;
  delete start;
  while (buf != NULL) {
    cout << (buf->n) << endl;
    end = buf;
    buf = buf->next;
    delete end;
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

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

  while (1) {
    int n, m, a;
    int ami[200][1000];
    cin >> n >> m >> a;
    if (n == 0 && m == 0 && a == 0)
      break;

    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 1000; j++) {
        ami[i][j] = -1;
      }
    }

    int height = -1;
    for (int i = 0; i < m; i++) {
      int h, p, q;
      cin >> h >> p >> q;
      height = max(height, h);
      ami[p][h] = q;
      ami[q][h] = p;
    }

    int pos = a;
    for (int i = height; i > 0; i--) {
      if (ami[pos][i] == -1) {

      } else {
        pos = ami[pos][i];
      }
    }
    cout << pos << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

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

  while (1) {
    int n, m, a;
    int ami[200][1000];
    cin >> n >> m >> a;
    if (n == 0 && m == 0 && a == 0)
      break;

    for (int i = 0; i <= 100; i++) {
      for (int j = 0; j <= 1000; j++) {
        ami[i][j] = -1;
      }
    }

    int height = -1;
    for (int i = 0; i < m; i++) {
      int h, p, q;
      cin >> h >> p >> q;
      height = max(height, h);
      ami[h][p] = q;
      ami[h][q] = p;
    }

    int pos = a;
    for (int i = height; i > 0; i--) {
      if (ami[i][pos] == -1) {

      } else {
        pos = ami[i][pos];
      }
    }
    cout << pos << endl;
  }

  return 0;
}