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

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> P;

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

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  map<string, int> mp;
  mp["N"] = 0;
  mp["E"] = 1;
  mp["W"] = 2;
  mp["S"] = 3;
  while (cin >> n, n) {
    vector<vector<bool>> exist(21, vector<bool>(21, false));
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      exist[x][y] = true;
    }
    int m;
    cin >> m;
    int x = 10, y = 10;
    int num_done = 0;
    rep(i, m) {
      string c;
      int step;
      cin >> c >> step;
      int k = mp[c];
      rep(j, step) {
        x += dx[k], y += dy[k];
        if (exist[x][y]) {
          exist[x][y] = false;
          num_done++;
        }
      }
    }
    cout << (num_done == n ? "Yes" : "No") << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define rrep2(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(a) (a).begin(), (a).end()

typedef long long ll;
typedef pair<int, int> P;

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

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  map<string, int> mp;
  mp["N"] = 0;
  mp["E"] = 1;
  mp["W"] = 2;
  mp["S"] = 3;
  while (cin >> n, n) {
    vector<vector<bool>> exist(21, vector<bool>(21, false));
    rep(i, n) {
      int x, y;
      cin >> x >> y;
      exist[x][y] = true;
    }
    int m;
    cin >> m;
    int x = 10, y = 10;
    int num_done = 0;
    rep(i, m) {
      string c;
      int step;
      cin >> c >> step;
      int k = mp[c];
      rep(j, step) {
        x += dx[k], y += dy[k];
        if (exist[x][y]) {
          exist[x][y] = false;
          num_done++;
        }
      }
    }
    cout << (num_done == n ? "Yes" : "No") << endl;
  }
}
Problem p01125 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, M, x, y, l, rx, ry;
  char d;
  while (cin >> N, N) {
    vector<vector<bool>> a(21, vector<bool>(21, false));
    rx = ry = 10;
    for (int i = 0; i < N; i++) {
      cin >> x >> y;
      a[x][y] = true;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
      cin >> d >> l;
      switch (d) {
      case 'N':
        for (int j = 0; j < l; j++) {
          ry++;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'S':
        for (int j = 0; j < l; j++) {
          ry--;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'E':
        for (int j = 0; j < l; j++) {
          rx++;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'W':
        for (int j = 0; j < l; j++) {
          rx--;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      }
    }
    for (int i = 0; i < 21; i++) {
      for (int j = 0; j < 21; j++) {
        if (a[i][j]) {
          cout << "No" << endl;
          goto rabel;
        }
      }
    }
    cout << "Yes" << endl;
  rabel:;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int N, M, x, y, l, rx, ry;
  char d;
  while (cin >> N, N) {
    vector<vector<bool>> a(20, vector<bool>(20, false));
    rx = ry = 10;
    for (int i = 0; i < N; i++) {
      cin >> x >> y;
      a[x][y] = true;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
      cin >> d >> l;
      switch (d) {
      case 'N':
        for (int i = 0; i < l; i++) {
          ry++;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'S':
        for (int i = 0; i < l; i++) {
          ry--;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'E':
        for (int i = 0; i < l; i++) {
          rx++;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      case 'W':
        for (int i = 0; i < l; i++) {
          rx--;
          if (a[rx][ry])
            a[rx][ry] = false;
        }
        break;
      }
    }
    for (int i = 0; i < 20; i++) {
      for (int j = 0; j < 20; j++) {
        if (a[i][j]) {
          cout << "NO" << endl;
          goto rabel;
        }
      }
    }
    cout << "YES" << endl;
  rabel:;
  }
  return 0;
}
Problem p01125 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  vector<string> r;
  while (true) {
    int gem = 0, gemgot = 0;
    int map[21][21] = {{0}};
    cin >> gem;
    if (gem == 0) {
      break;
    }
    for (int i = 0; i < gem; i++) {
      int x = 0, y = 0;
      scanf("%d %d", &x, &y);
      map[x][y] = 1;
    }
    int rx = 10, ry = 10;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int d = 0;
      int dx = 0, dy = 0;
      char dest[8];
      scanf("%s %d", dest, &d);
      if (dest[0] == 'N') {
        dy = 1;
      } else if (dest[0] == 'S') {
        dy = -1;
      } else if (dest[0] == 'W') {
        dx = -1;
      } else if (dest[0] == 'E') {
        dx = 1;
      }
      for (int j = 0; j < d; j++) {
        rx += dx;
        ry += dy;
        if (map[rx][ry] == 1) {
          map[rx][ry] = 0;
          gemgot++;
        }
      }
    }
    if (gem == gemgot) {
      r.push_back("Yes");
    } else {
      r.push_back("No");
    }
  }
  for (int i = 0; i < r.size(); i++) {
    cout << r[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main(void) {
  vector<string> r;
  while (true) {
    int gem = 0, gemgot = 0;
    int map[21][21] = {{0}};
    cin >> gem;
    if (gem == 0) {
      break;
    }
    for (int i = 0; i < gem; i++) {
      int x = 0, y = 0;
      scanf("%d %d", &x, &y);
      map[x][y] = 1;
    }
    int rx = 10, ry = 10;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      int d = 0;
      int dx = 0, dy = 0;
      char dest[1];
      scanf("%s %d", dest, &d);
      if (*dest == 'N') {
        dy = 1;
      } else if (*dest == 'S') {
        dy = -1;
      } else if (*dest == 'W') {
        dx = -1;
      } else if (*dest == 'E') {
        dx = 1;
      }
      for (int j = 0; j < d; j++) {
        rx += dx;
        ry += dy;
        if (rx > 20) {
          rx = 20;
        } else if (rx < 0) {
          rx = 0;
        }
        if (ry > 20) {
          ry = 20;
        } else if (ry < 0) {
          ry = 0;
        }
        if (map[rx][ry] == 1) {
          map[rx][ry] = 0;
          gemgot++;
        }
      }
    }
    if (gem == gemgot) {
      r.push_back("YES");
    } else {
      r.push_back("NO");
    }
  }
  for (int i = 0; i < r.size(); i++) {
    cout << r[i] << endl;
  }
  return 0;
}
Problem p01125 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N;
  while (cin >> N, N) {
    int map[21][21] = {};
    for (int i = 0; i < N; i++) {
      int x, y;
      cin >> x >> y;
      map[x][y] = 1;
    }

    int M;
    cin >> M;
    int X = 10, Y = 10;
    for (int i = 0; i < M; i++) {
      char d;
      int l;
      cin >> d >> l;
      for (int j = 0; j < l; j++) {
        if (d == 'N')
          Y++;
        else if (d == 'E')
          X++;
        else if (d == 'S')
          Y--;
        else if (d == 'W')
          X--;
        N -= map[X][Y];
        map[X][Y] = 0;
      }
    }
    if (N)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int N, M, x, y;
  pair<int, int> robot;
  int field[20][20];

  while (cin >> N, N) {
    for (int i = 0; i <= 20; i++)
      for (int j = 0; j <= 20; j++)
        field[i][j] = 0;
    robot.first = robot.second = 10;
    for (int i = 0; i < N; i++) {
      cin >> x >> y;
      field[x][y] = 1;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
      char drct;
      int dis;
      cin >> drct >> dis;
      if (drct == 'N') {
        for (int i = robot.second + 1; i <= robot.second + dis; i++) {
          field[robot.first][i] = 0;
        }
        robot.second += dis;
      } else if (drct == 'E') {
        for (int i = robot.first + 1; i <= robot.first + dis; i++) {
          field[i][robot.second] = 0;
        }
        robot.first += dis;
      } else if (drct == 'S') {
        for (int i = robot.second - dis + 1; i <= robot.second; i++) {
          field[robot.first][i] = 0;
        }
        robot.second -= dis;
      } else if (drct == 'W') {
        for (int i = robot.first - dis + 1; i <= robot.first; i++) {
          field[i][robot.second] = 0;
        }
        robot.first -= dis;
      }
    }
    int check = 0;
    for (int i = 0; i <= 20; i++)
      for (int j = 0; j <= 20; j++)
        check += field[i][j];

    if (check)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }

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


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int n, m, a;
  cin >> n >> m >> a;
  if (!(n | m | a))
    return false;
  vector<vector<int>> vv(1002, vector<int>(n, 0));
  for (int i = 0; i < 1002; i++) {
    for (int j = 0; j < n; j++) {
      vv[i][j] = j + 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int h, p, q;
    cin >> h >> p >> q;
    vv[h][p - 1] = q;
    vv[h][q - 1] = p;
  }
  for (int i = 1001; i >= 0; i--) {
    a = vv[i][a - 1];
  }
  cout << a << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

  return 0;
}


Error: 0

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {
  int n, m, a;
  cin >> n >> m >> a;
  if (!(n | m | a))
    return false;
  vector<vector<int>> vv(m + 2, vector<int>(n, 0));
  for (int i = 0; i < m + 2; i++) {
    for (int j = 0; j < n; j++) {
      vv[i][j] = j + 1;
    }
  }
  for (int i = 0; i < m; i++) {
    int h, p, q;
    cin >> h >> p >> q;
    vv[h][p - 1] = q;
    vv[h][q - 1] = p;
  }
  for (int i = m + 1; i >= 0; i--) {
    a = vv[i][a - 1];
  }
  cout << a << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

/*---------------------------------------------------*/

int n, m, a;

void solve() {
  int h, p, q;
  int num[1005];
  queue<pi> qp[1005];
  rep(i, 1005) num[i] = i;
  rep(i, m) {
    cin >> h >> p >> q;
    qp[h].push(make_pair(p, q));
  }

  rrep(i, 1004) {
    while (qp[i].size()) {
      pi tmp;
      tmp = qp[i].front();
      qp[i].pop();
      swap(num[tmp.first], num[tmp.second]);
    }
  }
  rep(i, 1005) if (num[i] == a) {
    cout << i << endl;
    break;
  }
}

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

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define INF 999999999
#define mod 1000000007

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define REP(i, a, b) for (int i = (a); i < int(b); i++)
#define all(x) (x).begin(), x.end()
#define pb push_back
#define MOD(x) (x % (mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pi;

/*---------------------------------------------------*/

int n, m, a;

void solve() {
  int num[1005];
  queue<pi> qp[1005];
  int h, p, q;
  rep(i, 1005) num[i] = i;
  rep(i, m) {
    cin >> h >> p >> q;
    qp[h].push(make_pair(p, q));
  }

  rrep(i, 1005) {
    while (qp[i].size()) {
      pi tmp;
      tmp = qp[i].front();
      qp[i].pop();
      swap(num[tmp.first], num[tmp.second]);
    }
  }
  rep(i, 1005) if (num[i] == a) {
    cout << i << endl;
    break;
  }
}

int main() {
  while (1) {
    cin >> n >> m >> a;
    if (n == 0 && m == 0 && a == 0)
      break;
    solve();
  }
  return 0;
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m, a;
set<P> f[1100];

int main() {
  while (cin >> n >> m >> a && n + m + a) {
    REP(i, 1100) f[i].clear();
    REP(i, m) {
      int h, p, q;
      cin >> h >> p >> q;
      f[h].insert(P(p, q));
      // f[h].insert(P(q, p));
    }
    int now = a;
    REP(i, 1000) {
      if (f[1000 - i].find(P(now - 1, now)) != f[1000 - i].end())
        now = now - 1;
      else if (f[1000 - i].find(P(now, now + 1)) != f[1000 - i].end())
        now = now + 1;
    }
    cout << now << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, N) for (int i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m, a;
set<P> f[110];

int main() {
  while (cin >> n >> m >> a && n + m + a) {
    REP(i, m) f[i].clear();
    REP(i, m) {
      int h, p, q;
      cin >> h >> p >> q;
      f[h].insert(P(p, q));
    }
    int now = a;
    REP(i, n) {
      if (f[n - 1 - i].find(P(a - 1, a)) != f[n - 1 - i].end())
        a = a - 1;
      else if (f[n - 1 - i].find(P(a, a + 1)) != f[n - 1 - i].end())
        a = a + 1;
      // cout << a << endl;
    }
    cout << a << endl;
  }
}
Problem p01126 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, a, h, p, q;
int y[1010][110];

int main() {
  while (cin >> n >> m >> a && n + m + a) {
    REP(i, 1010) REP(j, 110) y[i][j] = 0;
    REP(i, m) {
      cin >> h >> p >> q;
      y[h][p] = q;
      y[h][q] = p;
    }
    for (int i = 1000; i > 0; i--) {
      if (y[i][a] != 0)
        a = y[i][a];
    }
    cout << a << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, N) for (long long i = 0; i < (N); i++)
#define ALL(s) (s).begin(), (s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n, m, a, h, p, q;
vector<pair<int, int>> vp[1000];

int main() {
  while (cin >> n >> m >> a && n + m + a) {
    REP(i, n) {
      cin >> h >> p >> q;
      vp[h].push_back(P(p, q));
    }
    for (int i = m; i > 0; i--) {
      REP(j, vp[i].size()) {
        if (a = vp[i][j].first) {
          a = vp[i][j].second;
        } else if (a = vp[i][j].second) {
          a = vp[i][j].first;
        }
      }
    }
    cout << a << endl;
    REP(i, m) vp[i].clear();
  }
}
Problem p01126 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, m, a;
  while (cin >> n >> m >> a, (n or m or a)) {
    vector<pair<int, int>> amida[n];

    rep(i, m) {
      int h, p, q;
      cin >> h >> p >> q;
      p--;
      q--;
      amida[p].push_back({h, q});
      amida[q].push_back({h, p});
    }

    rep(i, n) {
      sort(amida[i].begin(), amida[i].end(), greater<pair<int, int>>());
    }

    int now_h = 1e8;
    bool update = true;
    a--;

    while (update) {
      update = false;
      for (auto t : amida[a]) {
        if (now_h > t.first) {
          now_h = t.first;
          a = t.second;
          update = true;
          break;
        }
      }
    }

    cout << a + 1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, m, a;
  while (cin >> n >> m >> a, (n or m or a)) {
    vector<pair<int, int>> amida[n];

    rep(i, m) {
      int h, p, q;
      cin >> h >> p >> q;
      p--;
      q--;
      amida[p].push_back({h, q});
      amida[q].push_back({h, p});
    }

    rep(i, n) {
      sort(amida[i].begin(), amida[i].end(), greater<pair<int, int>>());
    }

    int now_h = 1e8;
    bool update = true;
    a--;
    while (update) {
      update = false;
      for (auto t : amida[a]) {
        if (now_h >= t.first and a != t.second) {
          now_h = t.first;
          a = t.second;
          update = true;
        }
      }
    }

    cout << a + 1 << endl;
  }

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

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

struct line {
  int from;
  int to;
};

int main() {
  vector<vector<line>> amida;

  do {
    amida.clear();
    amida.resize(1001);
    int n, m, a;
    cin >> n >> m >> a;
    if (n == 0 && m == 0 && a == 0)
      return 0;

    int h, p, q;
    for (int loop = 0; loop < m; loop++) {
      line l;
      cin >> h >> p >> q;
      if (p > q) {
        int temp = p;
        p = q;
        q = temp;
      }
      l.from = p;
      l.to = q;
      amida[h].push_back(l);
    }

    for (int i = 1000; i > 0; i--) {
      for (int j = 0; j < amida[i].size(); j++) {
        if (amida[i][j].from == a) {
          a = amida[i][j].to;
          break;
        } else if (amida[i][j].to == a) {
          a = amida[i][j].from;
          break;
        }
      }
    }
    cout << a << endl;

  } while (1);
  return 0;
}

Error: 0

Fixed submission:

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

struct line {
  int from;
  int to;
};

int main() {
  vector<vector<line>> amida;
  int n, m, a;
  cin >> n >> m >> a;
  amida.resize(1001);

  int h, p, q;
  do {
    for (int loop = 0; loop < m; loop++) {
      line l;
      cin >> h >> p >> q;
      if (h == 0 && p == 0 && q == 0)
        return 0;
      if (p > q) {
        int temp = p;
        p = q;
        q = temp;
      }
      l.from = p;
      l.to = q;
      amida[h].push_back(l);
    }

    for (int i = 1000; i > 0; i--) {
      for (int j = 0; j < amida[i].size(); j++) {
        if (amida[i][j].from == a) {
          a = amida[i][j].to;
          break;
        }
      }
    }
    cout << a << endl;

    amida.clear();
  } while (1);
  return 0;
}