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

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n, arr[5000];
  std::vector<int> v;
  while (std::cin >> n, n) {
    std::fill(arr, arr + 5000, 0);
    v.clear();

    for (int i = 1; i <= (n - 1) / 2; i++) {
      if (std::find(v.begin(), v.end(), i * i % n) == v.end()) { // まだない
        v.push_back(i * i % n);
      }
    }

    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        int value = v[i] - v[j];
        if (value < 0) {
          value += n;
        }
        if (value > (n - 1) / 2) {
          value = n - value;
        }
        arr[value]++;
      }
    }

    for (int i = 1; i <= (n - 1) / 2; i++) {
      std::cout << arr[i] * 2 << std::endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int n, arr[5000];
  std::vector<int> v;
  while (std::cin >> n, n) {
    std::fill(arr, arr + 5000, 0);
    v.clear();

    for (int i = 1; i <= (n - 1) / 2; i++) {
      if (std::find(v.begin(), v.end(), i * i % n) == v.end()) { // まだない
        v.push_back(i * i % n);
      }
    }

    for (int i = 0; i < v.size() - 1; i++) {
      for (int j = i + 1; j < v.size(); j++) {
        int value = v[i] - v[j];
        if (value < 0) {
          value += n;
        }
        if (value > (n - 1) / 2) {
          value = n - value;
        }
        arr[value]++;
      }
    }

    for (int i = 1; i <= (n - 1) / 2; i++) {
      std::cout << arr[i] * 2 << std::endl;
    }
  }
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int n, a[10000];
bool p[10000];
int main() {
  while (scanf("%d", &n), n) {
    vector<int> v;
    memset(a, 0, sizeof(a));
    memset(p, 0, sizeof(p));
    for (int i = 1; i < n; i++)
      p[i * i % n] = true;
    for (int i = 0; i < n; i++) {
      if (p[i])
        v.push_back(i);
    }
    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        int r = v[j] - v[i];
        if (r < 0)
          r += n;
        if (r > n / 2)
          r = n - r;
        a[r - 1]++;
      }
    }
    for (int i = 0; i < n / 2; i++)
      printf("%d\\n", a[i] * 2);
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n;
int main() {
  while (scanf("%d", &n), n) {
    vector<int> v1, v2;
    for (int i = 1; i < n; i++)
      v1.push_back(i * i % n);
    sort(v1.begin(), v1.end());
    v2.push_back(v1[0]);
    for (int i = 1; i < v1.size(); i++) {
      if (v1[i - 1] != v1[i])
        v2.push_back(v1[i]);
    }
    vector<int> a(n / 2);
    for (int i = 0; i < v2.size(); i++) {
      for (int j = i + 1; j < v2.size(); j++) {
        int r = v2[j] - v2[i];
        if (r < 0)
          r += n;
        if (r > n / 2)
          r = n - r;
        a[r - 1]++;
      }
    }
    for (int i = 0; i < n / 2; i++)
      printf("%d\\n", a[i] * 2);
  }
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n, z;
vector<long long> p;

int main() {
  while (true) {
    for (int i = 0; i < MAX_N; i++) {
      q[i] = 0;
      x[i] = 0;
    }
    cin >> n;
    p.clear();
    if (n == 0) {
      break;
    }
    for (int i = 1; i < n; i++) {
      q[(i * i) % n] = 1;
    }
    for (int i = 0; i < MAX_N; i++) {
      if (q[i] == 1) {
        p.push_back(i);
      }
    }
    for (int i = 0; i < p.size(); i++) {
      for (int j = i + 1; j < p.size(); j++) {
        if (i != j) {
          z = p[i] - p[j];
          if (z < 0) {
            z += n;
          }
          if (z > (n - 1) / 2) {
            z = n - z;
          }
          x[z]++;
        }
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << x[i] * 2 << endl;
    }
  }
}

Error: WA

Fixed submission:

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

#define MAX_N 100000

long long q[MAX_N];
long long x[MAX_N];
long long n, z;
vector<long long> p;

int main() {
  while (true) {
    for (int i = 0; i < MAX_N; i++) {
      q[i] = 0;
      x[i] = 0;
    }
    cin >> n;
    p.clear();
    if (n == 0) {
      break;
    }
    for (int i = 1; i < n; i++) {
      q[(i * i) % n]++;
    }
    for (int i = 1; i < n; i++) {
      if (q[i] >= 1) {
        p.push_back(i);
      }
    }
    for (int i = 0; i < p.size(); i++) {
      for (int j = 0; j < p.size(); j++) {
        if (i != j) {
          z = p[i] - p[j];
          if (z < 0) {
            z += 11;
          }
          if (z > (n - 1) / 2) {
            z = 11 - z;
          }
          x[z]++;
        }
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << x[i] << endl;
    }
  }
}
Problem p00142 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> num;
    for (int i = 1; i < n; i++)
      num.push_back(i * i % n);
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    int ans[10001] = {};
    for (int i = 0; i < num.size(); i++) {
      for (int j = 0, k; j < num.size(); j++) {
        k = num[i] - num[j];
        if (k < 0)
          k += n;
        if (k > n / 2)
          k = n - k;
        ans[k]++;
      }
    }
    for (int i = 1; i <= n / 2; i++)
      cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> num;
    for (int i = 1; i < n; i++)
      num.push_back(i * i % n);
    sort(num.begin(), num.end());
    vector<int> number;
    number.push_back(num[0]);
    for (int i = 1; i < num.size(); i++)
      if (num[i] - num[i - 1] != 0)
        number.push_back(num[i]);
    int ans[10001] = {};
    for (int i = 0; i < number.size(); i++) {
      for (int j = 0, k; j < number.size(); j++) {
        k = number[i] - number[j];
        if (k < 0)
          k += n;
        if (k > n / 2)
          k = n - k;
        ans[k]++;
      }
    }
    for (int i = 1; i <= n / 2; i++)
      cout << ans[i] << endl;
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int number[10001];
  for (int i = 1; i < 10000; i++)
    number[i] = i * i;
  while (cin >> n, n) {
    vector<int> num;
    for (int i = 1; i < n; i++)
      num.push_back(number[i] % n);
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    int ans[5000] = {};
    for (int i = 0; i < num.size(); i++) {
      for (int j = 0, k; j < num.size(); j++) {
        k = num[i] - num[j];
        if (k < 0)
          k += n;
        if (k > n / 2)
          k = n - k;
        ans[k]++;
      }
    }
    for (int i = 1; i <= n / 2; i++)
      cout << ans[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int number[10001];
  for (int i = 1; i < 10000; i++)
    number[i] = i * i;
  while (cin >> n, n) {
    vector<int> num;
    for (int i = 1; i < n; i++)
      num.push_back(number[i] % n);
    sort(num.begin(), num.end());
    num.erase(unique(num.begin(), num.end()), num.end());
    int ans[5000] = {};
    for (int i = 0; i < num.size() - 1; i++) {
      for (int j = i + 1, k; j < num.size(); j++) {
        k = num[i] - num[j];
        if (k < 0)
          k += n;
        if (k > n / 2)
          k = n - k;
        ans[k]++;
      }
    }
    for (int i = 1; i <= n / 2; i++)
      cout << ans[i] * 2 << endl;
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef vector<II> VII;

template <class T> ostream &operator<<(ostream &os, vector<T> v) {
  for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) {
    os << *it_i << ", ";
  }
  return os;
}

typedef set<int> SI;

int B[10001];

int main() {
  int n;
  while (cin >> n && n) {
    SI A;
    for (int i = 1; i < n; ++i) {
      A.insert((i * i) % n);
    }
    fill(B, B + 10001, 0);
    for (SI::iterator it_i = A.begin(); it_i != A.end(); ++it_i) {
      for (SI::iterator it_j = it_i; it_j != A.end(); ++it_j) {
        if (*it_i == *it_j)
          continue;
        int sub = *it_i - *it_j;
        if (sub < 0)
          sub += n;
        if (sub * 2 > (n - 1))
          sub = n - sub;
        B[sub]++;
      }
    }
    for (int i = 1; 2 * i <= n - 1; ++i) {
      cout << B[i] * 2 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair<INT, INT> II;
typedef vector<II> VII;

template <class T> ostream &operator<<(ostream &os, vector<T> v) {
  for (typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i) {
    os << *it_i << ", ";
  }
  return os;
}

typedef set<int> SI;

int main() {
  int n;
  while (cin >> n && n) {
    SI A;
    for (int i = 1; i < n; ++i) {
      A.insert((i * i) % n);
    }
    map<int, int> B;
    for (SI::iterator it_i = A.begin(); it_i != A.end(); ++it_i) {
      for (SI::iterator it_j = A.begin(); it_j != A.end(); ++it_j) {
        if (it_i == it_j)
          continue;
        int sub = *it_i - *it_j;
        if (sub < 0)
          sub += n;
        if (sub * 2 > (n - 1))
          sub = n - sub;
        B[sub]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; ++i) {
      cout << B[i] << endl;
    }
  }
  return 0;
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int ok(int n) {
  if (n < 2)
    return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n;
  while (cin >> n, n) {
    set<int> r;
    for (int i = 1; i < n; i++)
      r.insert((i * i) % n);
    vector<int> wow;
    for (set<int>::iterator it = r.begin(); it != r.end(); ++it)
      wow.push_back(*it);
    int mp[10001] = {0};
    for (int i = 0; i < wow.size(); i++) {
      for (int j = 0; j < wow.size(); j++) {
        if (i == j)
          continue;
        int g = wow[i] - wow[j];
        if (g < 0)
          g += n;
        if (g > (n - 1) / 2)
          g = n - g;
        mp[g]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++)
      cout << mp[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

int ok(int n) {
  if (n < 2)
    return 0;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return 0;
  }
  return 1;
}
int main() {
  int n;
  while (cin >> n, n) {
    set<int> r;
    for (int i = 1; i < n; i++)
      r.insert((i * i) % n);
    vector<int> wow;
    for (set<int>::iterator it = r.begin(); it != r.end(); ++it)
      wow.push_back(*it);
    map<int, int> mp;
    for (int i = 0; i < wow.size(); i++) {
      for (int j = 0; j < wow.size(); j++) {
        if (i == j)
          continue;
        int g = wow[i] - wow[j];
        if (g < 0)
          g += n;
        if (g > (n - 1) / 2)
          g = n - g;
        mp[g]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++)
      cout << mp[i] << endl;
  }
}
Problem p00142 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    map<int, bool> m;
    for (int i = 1; i < n; i++) {
      m[(i * i) % n] = true;
    }
    vector<int> v;
    for (pair<int, bool> p : m) {
      v.push_back(p.first);
    }
    int cnt[11000] = {};
    for (int i = 0; i < v.size(); i++) {
      for (int j = 0; j < v.size(); j++) {
        if (i == j) {
          continue;
        }
        int num = v[i] - v[j];
        if (num < 0) {
          num += n;
        }
        if (num > (n - 1) / 2) {
          num = n - num;
        }
        cnt[num] += 1;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << cnt[i] << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int n, a[20000];

  bool exist[20000];

  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    if (n < 6) {
      while (true) {
      }
    }
    for (int i = 1; i < n; i++) {
      exist[i] = false;
      a[i] = 0;
    }
    for (int i = 1; i < n; i++) {
      exist[(i * i) % n] = true;
    }

    int dummy;

    for (int i = 1; i < n; i++) {
      for (int j = 1; j < n; j++) {
        if (i == j) {
          continue;
        }
        if (exist[i] && exist[j]) {
          dummy = i - j;
          if (dummy < 0) {
            dummy += n;
          }
          if (dummy > (n - 1) / 2) {
            dummy = n - dummy;
          }
          a[dummy]++;
        }
      }
    }

    for (int i = 1; i <= n / 2; i++) {
      printf("%d\\n", a[i]);
    }
  }

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

#include <iostream>
#include <math.h>

using namespace std;

double square_calc(double x1, double y1, double x2, double y2, double x3,
                   double y3) {
  double square = 0;
  double a = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  double b = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
  double c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
  double s = (a + b + c) / 2;
  return (sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
    cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
    double square = square_calc(xp1, yp1, xp2, yp2, xp3, yp3);
    double square1 = square_calc(xk, yk, xp1, yp1, xp2, yp2) +
                     square_calc(xk, yk, xp1, yp1, xp3, yp3) +
                     square_calc(xk, yk, xp2, yp2, xp3, yp3);
    double square2 = square_calc(xs, ys, xp1, yp1, xp2, yp2) +
                     square_calc(xs, ys, xp1, yp1, xp3, yp3) +
                     square_calc(xs, ys, xp2, yp2, xp3, yp3);
    if (fabs(square - square1) <= 1e-6 && fabs(square - square2) >= 1e-6 ||
        fabs(square - square1) >= 1e-6 && fabs(square - square2) <= 1e-6) {
      cout << "OK" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>

using namespace std;

double square_calc(double x1, double y1, double x2, double y2, double x3,
                   double y3) {
  double square = 0;
  double a = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  double b = sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
  double c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
  double s = (a + b + c) / 2;
  return (sqrt(s * (s - a) * (s - b) * (s - c)));
}

void solve() {
  int n;
  while (cin >> n, n) {
    for (int i = 0; i < n; ++i) {
      double xp1, yp1, xp2, yp2, xp3, yp3, xk, yk, xs, ys;
      cin >> xp1 >> yp1 >> xp2 >> yp2 >> xp3 >> yp3 >> xk >> yk >> xs >> ys;
      double square = square_calc(xp1, yp1, xp2, yp2, xp3, yp3);
      double square1 = square_calc(xk, yk, xp1, yp1, xp2, yp2) +
                       square_calc(xk, yk, xp1, yp1, xp3, yp3) +
                       square_calc(xk, yk, xp2, yp2, xp3, yp3);
      double square2 = square_calc(xs, ys, xp1, yp1, xp2, yp2) +
                       square_calc(xs, ys, xp1, yp1, xp3, yp3) +
                       square_calc(xs, ys, xp2, yp2, xp3, yp3);
      if (fabs(square - square1) <= 1e-6 && fabs(square - square2) >= 1e-6 ||
          fabs(square - square1) >= 1e-6 && fabs(square - square2) <= 1e-6) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    }
  }
}

int main() {
  solve();
  return (0);
}
Problem p00144 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <limits.h>
using namespace std;

int n;
int d[103][103];
void wf();

int main() {
  while (cin >> n)
    wf();
}

void wf() {
  int i1, m, J2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        d[i][j] = 0;
      d[i][j] = 1000000000; // INT_MAXツつセツづバツグツづゥ
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> i1 >> m;
    for (int j = 0; j < m; j++) {
      cin >> J2;
      d[i1 - 1][J2 - 1] = 1;
    }
  }

  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int oh;

  cin >> oh;
  int st, ed, ttl;
  for (int i = 0; i < oh; i++) {
    cin >> st >> ed >> ttl;
    if (d[st - 1][ed - 1] + 1 > ttl)
      cout << "NA" << endl;
    else
      cout << d[st - 1][ed - 1] + 1 << endl;

  } /*
  for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)cout << d[i][j] << " " ;
      cout << endl;
    }
    */
}


Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
int net[103][103], n, maxx = 0;
typedef pair<int, int> BVB;
int ans(int, int, int);

int main() {
  int num, n1, th, pkn, st, ed, c;

  cin >> n;

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

    cin >> num >> n1;
    if (num >= maxx)
      maxx = num;

    for (int j = 0; j < n1; j++) {
      cin >> th;
      net[num][th] = 1;
    }
  }

  for (int m = 0; m < maxx; m++)
    for (int n = 0; n < maxx; n++)
      if (net[m][n] != 1)
        net[m][n] = 0;

  cin >> pkn;

  for (int i = 0; i < pkn; i++) {
    cin >> st >> ed >> c;

    if (ans(st, ed, c) != -2)
      cout << ans(st, ed, c) << endl;
    else
      cout << "NA" << endl;
  }
}

int ans(int st, int ed, int c) {
  queue<BVB> Nari;
  int yes = 10001;
  BVB next, fr;

  fr.first = st;
  fr.second = c;
  Nari.push(fr);
  if (st == ed && c != 0)
    return 1;

  while (1) {
    next = Nari.front();

    Nari.pop();
    next.second = next.second - 1;

    if (fr.second == (next.second + 1) && next.second == 0 && next.first != ed)
      return -2;

    if (next.second < 0)
      break;

    for (int i = 1; i <= maxx; i++) {

      if (net[next.first][i] == 1 && i == ed) {

        if (yes > (c - next.second + 1))
          yes = (c - next.second) + 1;
      }

      if (net[next.first][i] == 1) {
        Nari.push(BVB(i, next.second));
      }
    }
  }
  if (yes != 10001) {
    return yes;
  } else
    return -2;
}
Problem p00144 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, a, b, c, d, k, DATA[101][101];
  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 101; j++) {
      DATA[i][j] = 1000000;
    }
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> k;
    for (int j = 0; j < k; j++) {
      cin >> b;
      DATA[a][b] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        if (DATA[j][k] > DATA[j][i] + DATA[i][k]) {
          DATA[j][k] = DATA[j][i] + DATA[i][k];
        }
      }
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (DATA[a][b] >= c)
      cout << "NA" << endl;
    else
      cout << DATA[a][b] + 1 << endl;
  }
  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, a, b, c, d, k, DATA[101][101];
  for (int i = 0; i <= 101; i++) {
    for (int j = 0; j <= 101; j++) {
      DATA[i][j] = 10000000;
    }
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> k;
    for (int j = 0; j < k; j++) {
      cin >> b;
      DATA[a][b] = 1;
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (k = 1; k <= n; k++) {
        if (DATA[j][k] > DATA[j][i] + DATA[i][k]) {
          DATA[j][k] = DATA[j][i] + DATA[i][k];
        }
      }
    }
  }

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    if (DATA[a][b] >= c)
      cout << "NA" << endl;
    else
      cout << DATA[a][b] + 1 << endl;
  }
  return 0;
}
Problem p00144 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <climits>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> NODE;
#define pos first
#define depth second

map<int, vector<int>> info;
int bfs(int s, int d) {
  queue<NODE> Q;
  map<int, bool> done;

  Q.push(make_pair(s, 0));
  while (!Q.empty()) {
    /* queueツづ個静ヲツ督ェツづ個ノツーツドツづーツ訪ツ姪「ツ催渉づ敖づ可つオツづowツ陛渉青板づ可禿シツづェツ、ツキツδーツつゥツづァツ偲ヲツづィツ渉慊つュ
     */
    NODE now = Q.front();
    Q.pop();
    done[now.pos] = true;

    if (now.pos == d) {
      return now.depth;
    }

    for (int i = 0; i < info[now.pos].size(); i++) {
      if (!done[info[now.pos][i]]) {
        Q.push(make_pair(info[now.pos][i], now.depth + 1));
      }
    }
  }
  return INT_MAX;
}

int main() {
  int n, r, k, t, p, s, d, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r >> k;
    for (int j = 0; j < k; j++) {
      cin >> t;
      info[r].push_back(t);
    }
  }

  cin >> p;
  for (int i = 0; i < p; i++) {
    cin >> s >> d >> v;

    if (v > bfs(s, d))
      cout << bfs(s, d) + 1 << endl;
    else
      cout << "NA" << endl;
  }
}

Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> NODE;
#define mp make_pair
bool connect[100][100];

int bfs(int s, int g, int t) {
  queue<NODE> Q;
  int ttl, pos;
  Q.push(mp(s, t));
  while (!Q.empty()) {
    pos = Q.front().first;
    ttl = Q.front().second;
    Q.pop();
    ttl--;
    if (pos == g)
      return ttl;
    if (ttl > 0)
      for (int i = 0; i < 100; i++)
        if (connect[pos][i])
          Q.push(mp(i, ttl));
  }
  return -1;
}

int main() {
  int n, r, k, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r >> k;
    r--;
    for (int j = 0; j < k; j++) {
      cin >> t;
      t--;
      connect[r][t] = true;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r >> k >> t;
    r--;
    k--;
    if (~bfs(r, k, t))
      cout << t - bfs(r, k, t) << endl;
    else
      cout << "NA" << endl;
  }
}