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

#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, ma;
  while (cin >> n, n) {
    string s[260];
    rep(i, n) cin >> s[i];
    ma = 0;
    rep(i, n) {
      rep(j, n) {
        if (s[i][j] == '1') {
          for (int k = 0; k <= n; k++) {
            if (j + k == n || s[i][j + k] == '0') {
              ma = max(ma, k);
              break;
            }
          }
          for (int k = 0; k <= n; k++) {
            if (i + k == n || s[i + k][j] == '0') {
              ma = max(ma, k);
              break;
            }
          }
          for (int k = 0; k <= n; k++) {
            if (i + k == n || j + k == n || s[i + k][j + k] == '0') {
              ma = max(ma, k);
              break;
            }
          }
          for (int k = 0; k <= n; k++) {
            if (i + k == n || j - k == -1 || s[i + k][j - k] == '0') {
              ma = max(ma, k);
              break;
            }
          }
        }
      }
    }
    cout << ma << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int n, ma;
  while (cin >> n, n) {
    string s[260];
    rep(i, n) cin >> s[i];
    ma = 0;
    rep(i, n) {
      rep(j, n) {
        if (s[i][j] == '1')
          for (int k = j;; k++) {
            if (s[i][k] == '0' || k == n) {
              ma = max(ma, k - j);
              j = k;

              break;
            }
          }
      }
      rep(j, n) {
        if (s[j][i] == '1')
          for (int k = 0;; k++) {
            if (s[j + k][i] == '0' || k + j == n) {
              ma = max(ma, k - j);
              j = k;
              break;
            }
          }
      }

      rep(j, n) {
        if (s[i][j] == '1') {
          for (int k = 0;; k++) {
            if (s[i + k][j + k] == '0' || k + i == n || k + j == n) {
              ma = max(ma, k);
              break;
            }
          }

          for (int k = 0;; k++) {
            if (i + k == n || j - k == -1 || s[i + k][j - k] == '0') {
              ma = max(ma, k);
              break;
            }
          }
        }
      }
    }
    cout << ma << endl;
  }
  return 0;
}
Problem p00151 (C++) — buggy submission, verdict: Runtime Error

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

#define SIZE 255

char M[SIZE][SIZE];

int main() {
  int n, mx, cnt;

  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> M[i][j];
      }
    }

    mx = 0;
    // x = k
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (M[i][j] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }

    // y = k
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (M[j][i] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }

    int I;
    // y = x + k
    for (int i = 0; i < 2 * n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        I = -j + i;
        if (0 <= I && I < n) {
          if (M[I][j] - '0') {
            cnt++;
            mx = max(mx, cnt);
          } else {
            cnt = 0;
          }
        }
      }
    }

    // y = -x + k
    for (int i = 0; i < 2 * n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        I = j + (-(n - 1) + i);
        if (0 <= I && I < n) {
          if (M[I][j] - '0') {
            cnt++;
            mx = max(mx, cnt);
          } else {
            cnt = 0;
          }
        }
      }
    }

    cout << mx << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

#define SIZE 255

char M[SIZE][SIZE];

int main() {
  int n, mx, cnt;

  while (cin >> n && n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> M[i][j];
      }
    }

    mx = 0;
    // tate
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (M[i][j] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    // yoko
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (M[j][i] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    // migishita
    for (int j = n - 1; j >= 0; j--) {
      cnt = 0;
      for (int i = 0; i < n - j; i++) {
        if (M[i + j][j] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }
    // hidarishita
    for (int i = n - 1; i >= 0; i--) {
      cnt = 0;
      for (int j = n - 1; j >= 0; j--) {
        if (M[i + j][j] - '0') {
          cnt++;
          mx = max(mx, cnt);
        } else {
          cnt = 0;
        }
      }
    }

    cout << mx << endl;
  }

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

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

char s[257][257];
int n;

int check(int i, int j) {
  int ii, jj;
  int count;
  count = 0;
  for (ii = 1; ii < n - i; ii++)
    if (s[i + ii][j] == '0')
      break;
  if (ii > count)
    count = ii;
  for (jj = 1; jj < n - j; jj++)
    if (s[i][j + jj] == '0')
      break;
  if (jj > count)
    count = jj;
  for (ii = 1, jj = 1; ii < n - i && jj < n - j; ii++, jj++)
    if (s[i + ii][j + jj] == '0')
      break;
  if (ii > count)
    count = ii;
  for (ii = 1, jj = 1; ii <= i && jj < n - j; ii++, jj++)
    if (s[i - ii][j + jj] == '0')
      break;
  if (ii > count)
    count = ii;
  return count;
}

int main() {
  int i, j;
  int max, t;
  while (scanf("%d", &n) != EOF, n) {
    for (i = 0; i < n; i++)
      scanf("%s", s[i]);
    max = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++) {
        if (s[i][j] == '1') {
          t = check(i, j);
          if (max < t)
            max = t;
        }
      }
    printf("%d\\n", max);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int check(vector<string> s, int i, int j, int n) {
  if (s[i][j] == '0')
    return 0;
  int ii, jj;
  int count;
  count = 0;
  for (ii = 1; ii < n - i; ii++)
    if (s[i + ii][j] == '0')
      break;
  if (ii > count)
    count = ii;
  for (jj = 1; jj < n - j; jj++)
    if (s[i][j + jj] == '0')
      break;
  if (jj > count)
    count = jj;
  for (ii = 1, jj = 1; ii < n - i && jj < n - j; ii++, jj++)
    if (s[i + ii][j + jj] == '0')
      break;
  if (ii > count)
    count = ii;
  for (ii = 1, jj = 1; ii <= i && jj < n - j; ii++, jj++)
    if (s[i - ii][j + jj] == '0')
      break;
  if (ii > count)
    count = ii;
  return count;
}

int main() {
  int n, i, j;
  int max, t;
  vector<string> s;
  while (cin >> n, n) {
    s.clear();
    s.resize(n);
    for (i = 0; i < n; i++)
      cin >> s[i];
    max = 0;
    for (i = 0; i < n; i++)
      for (j = 0; j < n; j++) {
        t = check(s, i, j, n);
        if (max < t)
          max = t;
      }
    cout << max << endl;
  }
  return 0;
}
Problem p00151 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define maxup(a, b) (a = max(a, b))
#define minup(a, b) (a = min(a, b))
#define INF 999999999
int n;

int main() {
  int n;
  while (cin >> n && n) {
    int dp[256][256][4];
    rep(i, 256) rep(j, 256) rep(k, 4) dp[i][j][k] = 0;
    vector<string> data(n);
    rep(i, n) cin >> data[i];

    rep(i, n) {
      rep(j, n) {
        if (data[i][j] == '1') {
          if (j - 1 >= 0)
            dp[i][j][0] = dp[i][j - 1][0] + 1;
          else
            dp[i][j][0] = 1;
          if (i - 1 >= 0 && j - 1 >= 0)
            dp[i][j][1] = dp[i - 1][j - 1][1] + 1;
          else
            dp[i][j][1] = 1;
          if (i - 1 >= 0)
            dp[i][j][2] = dp[i - 1][j][2] + 1;
          else
            dp[i][j][2] = 1;
          if (i - 1 >= 0 && j + 1 >= 0)
            dp[i][j][3] = dp[i - 1][j + 1][3] + 1;
          else
            dp[i][j][3] = 1;
        }
      }
    }
    int maxi = -1;
    rep(i, n) {
      rep(j, n) {
        rep(k, 4) { maxup(maxi, dp[i][j][k]); }
      }
    }
    cout << maxi << endl;
  }
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define maxup(a, b) (a = max(a, b))
#define minup(a, b) (a = min(a, b))
#define INF 999999999

int n;

int exe(int y, int x, int dy, int dx, vector<string> data) {
  int tmp = 0;
  while (1) {
    if (!(x >= 0 && y >= 0 && x < n && y < n)) {
      break;
    }
    tmp += data[y][x] - '0';
    x += dx, y += dy;
  }
  return tmp;
}

int solve(int y, int x, vector<string> data) {
  int lu = 0, ld = 0;
  int ru = 0, rd = 0;

  rd = exe(y, x, 1, 1, data);
  ru = exe(y, x, -1, 1, data);
  ld = exe(y, x, 1, -1, data);
  lu = exe(y, x, -1, -1, data);

  return max(rd + lu, ru + ld) - (data[y][x] - '0');
}

int main() {
  while (cin >> n && n) {
    vector<string> data(n);
    rep(i, n) cin >> data[i];

    int maxi = -1;
    rep(i, n) {
      int tmp = 0;
      rep(j, n) { tmp += data[i][j] - '0'; }
      maxup(maxi, tmp);
    }
    rep(i, n) {
      int tmp = 0;
      rep(j, n) { tmp += data[j][i] - '0'; }
      maxup(maxi, tmp);
    }

    rep(i, n) {
      rep(j, n) { maxup(maxi, solve(i, j, data)); }
    }
    cout << maxi << endl;
  }
}
Problem p00151 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n && n) {
    vector<string> map(n);
    for (int i = 0; i < n; i++)
      cin >> map[i];

    int answer = 0;
    int cnt;

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (map[i][j] == '0')
          continue;

        cnt = 0;
        while (i + cnt < n) {
          if (map[i + cnt][j] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);

        cnt = 0;
        while (j + cnt < n) {
          if (map[i][j + cnt] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);

        cnt = 0;
        while (i + cnt < n && j + cnt < n) {
          if (map[i + cnt][j + cnt] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);

        cnt = 0;
        while (i + cnt < n && j - cnt >= 0) {
          if (map[i + cnt][j - cnt] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);
      }
    }

    cout << answer << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  int n;
  while (cin >> n && n) {
    vector<string> map(n);
    for (int i = 0; i < n; i++)
      cin >> map[i];

    int answer = 0;
    int cnt;
    for (int i = 0; i < n; i++) {
      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (map[j][i] == '1')
          cnt++;
      }
      answer = max(answer, cnt);

      cnt = 0;
      for (int j = 0; j < n; j++) {
        if (map[i][j] == '1')
          cnt++;
      }
      answer = max(answer, cnt);
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cnt = 0;
        while (i + cnt < n && j + cnt < n) {
          if (map[i + cnt][j + cnt] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);

        cnt = 0;
        while (i + cnt >= 0 && j - cnt < n) {
          if (map[i + cnt][j - cnt] == '0')
            break;
          cnt++;
        }
        answer = max(cnt, answer);
      }
    }

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

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int n;

  while (scanf("%d", &n) && n) {
    vector<pair<int, int>> v;

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

      int frame = 0;
      int frameScore[10] = {0}, remain[10] = {0};
      int prev = -1;
      int ct = 0;
      while (frame < 10) {
        int pin;
        scanf("%d", &pin);
        frameScore[frame] += pin;

        if (frame == 9) {
          if (ct == 1 && frameScore[frame] < 10)
            frame++;
          else if (ct == 2)
            frame++;
          ct++;
        }

        for (int j = 0; j < 10; j++) {
          if (remain[j]) {
            frameScore[j] += pin;
            remain[j]--;
          }
        }

        if (frame < 9) {
          if (prev + pin == 10) {
            remain[frame] = 1;
            frame++;
            prev = -1;
          } else if (pin == 10) {
            remain[frame] = 2;
            frame++;
            prev = -1;
          } else if (~prev) {
            frame++;
            prev = -1;
          } else if (prev == -1)
            prev = pin;
        }
      }

      int sum = 0;
      for (int j = 0; j < 10; j++)
        sum += frameScore[j];
      v.push_back(make_pair(-sum, stNo));
    }

    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
      printf("%d %d\\n", v[i].second, -v[i].first);
    }
  }

  return (0);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

int main() {
  int n;

  while (scanf("%d", &n) && n) {
    vector<pair<int, int>> v;

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

      int frame = 0;
      int frameScore[10] = {0}, remain[10] = {0};
      int prev = -1;
      int ct = 0;
      while (frame < 10) {
        int pin;
        scanf("%d", &pin);
        frameScore[frame] += pin;

        if (frame == 9) {
          if (ct == 1 && frameScore[frame] < 10)
            frame++;
          else if (ct == 2)
            frame++;
          ct++;
        }

        for (int j = 0; j < 10; j++) {
          if (remain[j]) {
            frameScore[j] += pin;
            remain[j]--;
          }
        }

        if (frame < 9) {
          if (pin == 10 && prev != -1)
            return (1);
          if (pin == 10) {
            remain[frame] = 2;
            frame++;
            prev = -1;
          } else if (prev + pin == 10) {
            remain[frame] = 1;
            frame++;
            prev = -1;
          } else if (~prev) {
            frame++;
            prev = -1;
          } else if (prev == -1)
            prev = pin;
        }
      }

      int sum = 0;
      for (int j = 0; j < 10; j++)
        sum += frameScore[j];
      v.push_back(make_pair(-sum, stNo));
    }

    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
      printf("%d %d\\n", v[i].second, -v[i].first);
    }
  }

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

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

int a[8][1001];
int main() {
  int b;
  while (cin >> b, b) {
    memset(a, 0, sizeof(a));
    for (int c = 0; c < b; c++) {
      a[c][0] = 1;
      int d, e;
      cin >> d >> e;
      for (int f = 0; f <= e; f++) {
        for (int g = max(f * d, 1); g <= 1000; g++) {
          a[c + 1][g] += a[c][g - f * d];
        }
      }
    }
    int s;
    cin >> s;
    for (int n = 0; n < s; n++) {
      int w;
      cin >> w;
      cout << a[b][w] << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int a[8][1000];
int main() {
  int b;
  while (cin >> b, b) {
    memset(a, 0, sizeof(a));
    for (int c = 0; c < b; c++) {
      a[c][0] = 1;
      int d, e;
      cin >> d >> e;
      for (int f = 0; f <= e; f++) {
        for (int g = max(f * d, 1); g <= 1000; g++) {
          a[c + 1][g] += a[c][g - f * d];
        }
      }
    }
    int s;
    cin >> s;
    for (int n = 0; n < s; n++) {
      int w;
      cin >> w;
      cout << a[b][w] << endl;
    }
  }
}
Problem p00154 (C++) — buggy submission, verdict: Runtime Error

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

int a[11];
int b[11];
int dp
    [11]
    [1010]; // xテ、ツサツ・テ、ツクツ凝」ツ?ョテ」ツつォテ」ツδシテ」ツδ嘉」ツ?ョテ」ツ?ソテ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテヲツ閉ーyテ」ツ?ォテ」ツ?ェテ」ツつ凝」ツδ妥」ツつソテ」ツδシテ」ツδウテヲツ閉ー

int main() {
  int m;

  while (cin >> m && m) {
    for (int i = 0; i < m; i++) {
      cin >> a[i] >> b[i];
    }

    fill(dp[0], dp[8], 0);
    dp[0][0] = 1;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 1001; j++) {
        if (dp[i][j]) {
          for (int k = 0; k <= b[i]; k++) {
            if (j + k * a[i] <= 1000)
              dp[i + 1][j + k * a[i]] += dp[i][j];
          }
        }
      }
    }

    int g;
    cin >> g;
    for (int i = 0; i < g; i++) {
      int q;
      cin >> q;
      cout << dp[m][q] << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int a[11];
int b[11];
int dp
    [11]
    [1010]; // xテ、ツサツ・テ、ツクツ凝」ツ?ョテ」ツつォテ」ツδシテ」ツδ嘉」ツ?ョテ」ツ?ソテ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテヲツ閉ーyテ」ツ?ォテ」ツ?ェテ」ツつ凝」ツδ妥」ツつソテ」ツδシテ」ツδウテヲツ閉ー

int main() {
  int m;

  while (cin >> m && m) {
    fill(a, a + 10, 0);
    fill(a, b + 10, 0);
    for (int i = 0; i < m; i++) {
      cin >> a[i] >> b[i];
    }

    fill(dp[0], dp[10], 0);
    dp[0][0] = 1;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < 1001; j++) {
        if (dp[i][j]) {
          for (int k = 0; k <= b[i]; k++) {
            if (j + k * a[i] <= 1000)
              dp[i + 1][j + k * a[i]] += dp[i][j];
          }
        }
      }
    }

    int g;
    cin >> g;
    for (int i = 0; i < g; i++) {
      int q;
      cin >> q;
      cout << dp[m][q] << endl;
    }
  }

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

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

#define MAX_N 82000
#define MAX_CARD 100

long long dp[MAX_CARD][MAX_N];
long long card[MAX_CARD][2];
int n, m, a, b, cnt, sum;

int main() {
  while (true) {
    memset(dp, 0, sizeof(dp));
    memset(card, 0, sizeof(card));
    // cin.
    cin >> n;
    if (n == 0) {
      break;
    }
    cnt = 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      card[i][0] = a;
      card[i][1] = b;
      for (int j = 0; j < b; j++) {
        sum += a;
      }
    }
    // dp.
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= sum; j++) {
        if (dp[i - 1][j] != 0) {
          for (int k = 0; k <= card[i - 1][1]; k++) {
            dp[i][j + k * card[i - 1][0]] += dp[i - 1][j];
          }
        }
      }
    }
    // cin2.
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> a;
      cout << dp[n][a] << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

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

#define MAX_N 150000
#define MAX_CARD 120

long long dp[MAX_CARD][MAX_N];
long long card[MAX_CARD][2];
int n, m, a, b, cnt, sum;

int main() {
  while (true) {
    memset(dp, 0, sizeof(dp));
    memset(card, 0, sizeof(card));
    // cin.
    cin >> n;
    if (n == 0) {
      break;
    }
    cnt = 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a >> b;
      card[i][0] = a;
      card[i][1] = b;
      for (int j = 0; j < b; j++) {
        sum += a;
      }
    }
    // dp.
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= sum; j++) {
        if (dp[i - 1][j] != 0) {
          for (int k = 0; k <= card[i - 1][1]; k++) {
            dp[i][j + k * card[i - 1][0]] += dp[i - 1][j];
          }
        }
      }
    }
    // cin2.
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> a;
      cout << dp[n][a] << endl;
    }
  }
  return 0;
}
Problem p00155 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef double ll;
typedef pair<double, int> P;
int n;
ll G[101][101];

void dijkstra(int s, int g) {
  ll D[101];
  int from[101];
  for (int i = 0; i < 101; i++)
    D[i] = INF;
  priority_queue<P, vector<P>, greater<P>> Q;
  D[s] = 0;
  Q.push(P(0, s));

  while (!Q.empty()) {
    P t = Q.top();
    Q.pop();
    int pos = t.second;
    ll cost = t.first;
    if (pos == g)
      break;
    if (D[pos] < cost)
      continue;

    for (int i = 0; i < n; i++) {
      if (G[pos][i] == -1 || i == pos)
        continue;
      if (cost + G[pos][i] < D[i]) {
        Q.push(P(cost + G[pos][i], i));
        D[i] = cost + G[pos][i];
        from[i] = pos;
      }
    }
  }

  if (D[g] == INF) {
    cout << "NA" << endl;
    return;
  }

  vector<int> res;
  res.push_back(g);
  int pos = g;
  while (pos != s) {
    pos = from[pos];
    res.push_back(pos);
  }

  for (int i = 0; i < res.size(); i++) {
    if (i)
      cout << " ";
    cout << res[res.size() - 1 - i] + 1;
  }
  cout << endl;
}

int main() {
  while (cin >> n, n) {
    ll x[101], y[101];
    for (int i = 0; i < n; i++) {
      int b;
      cin >> b;
      cin >> x[b - 1] >> y[b - 1];
    }

    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        ll X = (x[i] - x[j]);
        ll Y = (y[i] - y[j]);
        ll dis = sqrt(X * X + Y * Y);
        if (dis > 50)
          G[i][j] = G[j][i] = -1;
        else
          G[i][j] = G[j][i] = dis;
      }

    int m;
    cin >> m;
    while (m--) {
      int s, g;
      cin >> s >> g;
      dijkstra(s - 1, g - 1);
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define INF 1000000000000LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;
double G[101][101];

void dijkstra(int s, int g) {
  int cost[101] = {};
  memset(cost, -1, sizeof(cost));
  cost[s] = 0;
  int from[101] = {};
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int pos = Q.front();
    Q.pop();

    for (int i = 0; i < n; i++) {
      if (G[pos][i] == 0 || cost[i] != -1)
        continue;
      Q.push(i);
      cost[i] = cost[pos] + 1;
      from[i] = pos;
    }
  }

  vector<int> res;
  res.push_back(g);
  int pos = g;
  while (pos != s) {
    pos = from[pos];
    res.push_back(pos);
  }

  for (int i = 0; i < res.size(); i++) {
    if (i)
      cout << " ";
    cout << res[res.size() - 1 - i] + 1;
  }
  cout << endl;
}

int main() {
  while (cin >> n, n) {
    double x[101], y[101];
    for (int i = 0; i < n; i++) {
      int b;
      cin >> b;
      cin >> x[b - 1] >> y[b - 1];
    }

    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++) {
        ll X = (x[i] - x[j]);
        ll Y = (y[i] - y[j]);
        ll dis = X * X + Y * Y;
        G[i][j] = G[j][i] = (dis <= 50 * 50);
      }

    int m;
    cin >> m;
    while (m--) {
      int s, g;
      cin >> s >> g;
      dijkstra(s - 1, g - 1);
    }
  }
  return 0;
}