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

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a + b == 0)
      break;
    int m[1100], w = 0, o[1100], c = 0;
    r(i, a) cin >> m[i];
    r(i, b) cin >> o[i];
    r(i, b) {
      c++;
      w += o[i];
      w += m[w];
      if (w >= a)
        break;
    }
    cout << c << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a + b == 0)
      break;
    int m[a], w = 0, o[b], c = 0;
    r(i, a) cin >> m[i];
    r(i, b) cin >> o[i];
    r(i, b) {
      c++;
      w += o[i];
      w += m[w];
      if (w >= a)
        break;
    }
    cout << c << endl;
  }
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int t[2000], n, m, a, ans, pos;
void init() {
  for (int i = 0; i < 2000; i++)
    t[i] = 0;
}
int main() {
  while (cin >> n >> m && n && m) {
    init();
    for (int i = 0; i < n; i++)
      cin >> t[i];
    ans = -1, pos = 0;
    for (int i = 0; i < m; i++) {
      cin >> a;
      if (ans == -1) {
        pos += a;
        if (pos >= n - 1 && ans == -1)
          ans = i + 1;
        pos += t[pos];
        if (pos >= n - 1 && ans == -1)
          ans = i + 1;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int t[2000], n, m, a, ans, pos;
void init() {
  for (int i = 0; i < 2000; i++)
    t[i] = 0;
}
int main() {
  while (cin >> n >> m && n && m) {
    init();
    for (int i = 0; i < n; i++)
      cin >> t[i];
    ans = -1, pos = 0;
    for (int i = 0; i < m; i++) {
      cin >> a;
      pos += a;
      if (pos >= n - 1 && ans == -1)
        ans = i + 1;
      pos += t[pos];
      if (pos >= n - 1 && ans == -1)
        ans = i + 1;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00467 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0)
      break;
    int mas[n], me[m];
    for (int i = 0; i < n; i++)
      scanf("%d", &mas[i]);
    for (int i = 0; i < m; i++)
      scanf("%d", &me[i]);
    int pos = 1, step = 0;
    while (pos < n) {
      pos = max(1, pos + me[step] + mas[pos + me[step] - 1]);
      step++;
    }
    printf("%d\\n", step);
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main(void) {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0)
      break;
    int mas[n], me[m];
    for (int i = 0; i < n; i++)
      scanf("%d", &mas[i]);
    for (int i = 0; i < m; i++)
      scanf("%d", &me[i]);
    int pos = 1, step = 0;
    while (pos < n) {
      pos = max(0, me[step] + mas[pos + me[step]]);
      step++;
    }
    printf("%d\\n", step);
  }

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

#include <stdio.h>

int main(void) {
  int n, m;
  int i;
  int pd[1000];
  int dd[1000];
  int prog;
  int ans;

  while (1) {
    scanf("%d %d", &n, &m);

    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &pd[i]);
    }

    for (i = 0; i < m; i++) {
      scanf("%d", &dd[i]);
    }

    prog = 1;
    i = 0;
    ans = 0;
    while (prog < n) {
      prog += dd[i];
      prog += pd[prog - 1];

      i++;
      ans++;
    }

    printf("%d\\n", ans);
  }

  return (0);
}

Error: WA

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, m;
  int i;
  int pd[1000];
  int dd[1000];
  int prog;
  int ans;

  while (1) {
    scanf("%d %d", &n, &m);

    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < n; i++) {
      scanf("%d", &pd[i]);
    }
    for (i = 0; i < m; i++) {
      scanf("%d", &dd[i]);
    }

    prog = 0;
    i = 0;
    ans = 0;
    while (prog < n) {
      prog += dd[i];
      prog += pd[prog];

      i++;
      ans++;
    }

    printf("%d\\n", ans);
  }

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

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

int main() {

  // ifstream cin("INPUT.txt");
  // ofstream cout("OUTPUT.txt");

  int n, m, i, j;
  int command[1001] = {0};
  int pos;
  int dice[1001] = {0};

  while (cin >> n >> m, n != 0 || m != 0) {

    for (i = 1; i <= n; i++) {
      cin >> command[i];
    }
    for (i = 1; i <= m; i++) {
      cin >> dice[i];
    }
    pos = 1;
    for (i = 1; i <= m; i++) {
      pos += dice[i];
      if (pos < n)
        pos += command[pos];
      if (pos >= n) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  // ifstream cin("INPUT.txt");
  // ofstream cout("OUTPUT.txt");

  int n, m, i, j;
  int command[1000] = {0};
  int pos;
  int dice;

  while (cin >> n >> m, n != 0 || m != 0) {

    pos = 1;
    for (i = 1; i <= n; i++) {
      cin >> command[i];
    }
    for (i = 1; i <= m; i++) {
      cin >> dice;
      pos += dice;
      pos += command[pos];
      if (pos >= n) {
        cout << i << endl;
        break;
      }
    }
  }

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

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

int main() {
  while (1) {
    int a, b;
    cin >> a >> b;
    if (!a && !b)
      break;
    vector<int> s(a);
    for (int b = 0; b < a; b++) {
      int c;
      cin >> c;
      s[b] = c;
    }
    int m = 0;
    int l = 0;
    vector<int> r(b);
    for (int j = 0; j < b; j++) {
      int w;
      cin >> w;
      r[j] = w;
    }
    while (1) {
      l++;
      int d;
      d = r[l - 1];
      m += d;
      if (m >= (a - 1)) {
        cout << l << endl;
        break;
      }
      m += s[m];
      if (m >= (a - 1)) {
        cout << l << endl;
        break;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int a, b;
    cin >> a >> b;
    if (!a && !b)
      break;
    vector<int> s(a);
    for (int b = 0; b < a; b++) {
      int c;
      cin >> c;
      s[b] = c;
    }
    int m = 0;
    int l = 0;
    while (1) {
      l++;
      int d;
      cin >> d;
      m += d;
      if (m >= (a - 1)) {
        cout << l << endl;
        break;
      }
      m += s[m];
      if (m >= (a - 1)) {
        cout << l << endl;
        break;
      }
    }
  }
}
Problem p00468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int x[10000], y[10000], f[10000];
int main() {
  int n, m, i, cnt1 = 0, cnt2, j;
  while (1) {
    int p[501] = {0};
    p[1] = 1;
    cnt1 = 0;
    scanf("%d %d", &n, &m);
    if (n == 0 && m == 0) {
      break;
    }
    for (i = 0; i < m; i++) {
      scanf("%d %d", &x[i], &y[i]);
      if (x[i] == 1 && p[y[i]] == 0) {
        p[y[i]] = 1;
        f[cnt1] = y[i];
        cnt1++;
      }
      if (y[i] == 1 && p[x[i]] == 0) {
        p[x[i]] = 1;
        f[cnt1] = x[i];
        cnt1++;
      }
    }
    cnt2 = cnt1;
    for (i = 0; i < cnt2; i++) {
      for (j = 0; j < m; j++) {
        if (f[i] == x[j] && p[y[j]] == 0) {
          p[y[j]] = 1;
          cnt1++;
        }
        if (f[i] == y[j] && p[x[j]] == 0) {
          p[x[j]] = 1;
          cnt1++;
        }
      }
    }
    printf("%d\\n", cnt1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  while (1) {

    int n, m, a[500], b[500], s1[500] = {}, s2[500] = {}, a1, b1, c1 = 0,
                              c2 = 0, i, j;

    cin >> n;
    cin >> m;

    if (n == 0 && m == 0) {
      break;
    }

    for (i = 0; i < m; i++) {

      cin >> a1 >> b1;

      if (a1 == 1) {
        s1[b1]++;
        s2[b1]++;
      }

      else if (a1 <= 0 || a1 > n || b1 <= 0 || b1 > n) {
        i--;
      }

      else {
        a[c1] = a1;
        b[c1] = b1;
        c1++;
      }
    }

    for (i = 1; i <= n; i++) {

      if (s1[i] > 0) {
        for (j = 0; j < c1; j++) {

          if (i == a[j]) {
            s2[b[j]]++;
          }
        }
      }
    }

    for (i = 1; i <= n; i++) {

      if (s2[i] > 0) {
        c2++;
      }
    }

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

#include <iostream>
#include <queue>

using namespace std;

int main() {

  while (1) {
    queue<int> Q;
    int n, m, a[10000][2], b, i, j, k;
    bool c[500] = {};
    cin >> n >> m;
    if (n == 0 && m == 0) {
      return 0;
    }
    for (j = 0, i = 0; i < m; i++) {
      cin >> a[i][0] >> a[i][1];
      if (a[i][0] == 1) {
        c[a[i][1] - 1] = true;
        Q.push(a[i][1]);
      } else if (a[i][1] == 1) {
        c[a[i][0] - 1] = true;
        Q.push(a[i][0]);
      }
    }
    for (; Q.size() != 0;) {
      b = Q.front();
      Q.pop();
      for (j = 0; j < m; j++) {
        if (b == a[j][0]) {
          c[a[j][1] - 1] = true;
        }
        if (b == a[j][1]) {
          c[a[j][0] - 1] = true;
        }
      }
    }
    int count = 0;
    for (i = 0; i < 500; i++) {
      if (c[i] == true) {
        count++;
      }
    }
    cout << count - 1 << "\\n";
  }
}


Error: WA

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

queue<int> Q;

int main() {
  int n, m, a[10000][2], b, i, j, k;
  bool c[500] = {};
  while (1) {

    cin >> n >> m;
    if (n == 0 && m == 0) {
      return 0;
    }
    for (i = 0; i < 500; i++) {
      c[i] = 0;
    }
    for (j = 0, i = 0; i < m; i++) {
      cin >> a[i][0] >> a[i][1];
      if (a[i][0] == 1) {
        c[a[i][1]] = true;
        Q.push(a[i][1]);
      } else if (a[i][1] == 1) {
        c[a[i][0]] = true;
        Q.push(a[i][0]);
      }
    }
    for (; Q.size() != 0;) {
      b = Q.front();
      Q.pop();
      for (j = 0; j < m; j++) {
        if (b == a[j][0]) {
          c[a[j][1]] = true;
        } else if (b == a[j][1]) {
          c[a[j][0]] = true;
        }
      }
    }
    int count = 0;
    for (i = 0; i < m; i++) {
      if (c[i] == true) {
        count++;
      }
    }
    cout << count << "\\n";
  }
}
Problem p00468 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;
const int inf = 1e8;

int main() {

  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    int a[m], b[m];
    for (int i = 0; i < m; i++) {
      cin >> a[i] >> b[i];
      a[i]--;
      b[i]--;
    }

    int mtrx[n][n];
    fill(mtrx[0], mtrx[n], inf);
    for (int i = 0; i < m; i++) {
      mtrx[a[i]][b[i]] = mtrx[b[i]][a[i]] = 1;
    }

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

    int ans = 0;
    for (int i = 1; i < n; i++) {
      if (mtrx[0][i] == 2 || mtrx[0][i] == 1)
        ans++;
    }

    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;
const int inf = 1e8;
int mtrx[500][500];

int main() {

  while (1) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    vector<int> a(n), b(n);
    for (int i = 0; i < m; i++) {
      cin >> a[i] >> b[i];
      a[i]--;
      b[i]--;
    }

    fill(mtrx[0], mtrx[n], inf);
    for (int i = 0; i < m; i++) {
      mtrx[a[i]][b[i]] = 1;
    }

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (mtrx[0][i] <= 2)
        ans++;
    }

    cout << ans << endl;
  }

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

// 34
#include <algorithm>
#include <iostream>

using namespace std;

void con(bool *i, bool (*f)[501], int n, int r) {
  i[n] = true;
  if (r) {
    for (int j = 1; j < 501; j++) {
      if (f[n][j]) {
        con(i, f, j, r - 1);
      }
    }
  }
}

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    bool f[501][501] = {{}};
    while (m--) {
      int a, b;
      cin >> a >> b;
      f[a][b] = f[b][a] = true;
    }
    bool inv[501] = {};
    con(inv, f, 1, 2);
    cout << count(inv + 2, inv + n + 1, true) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

// 34
#include <algorithm>
#include <iostream>

using namespace std;

void con(bool *i, bool (*f)[101], int n, int r) {
  i[n] = true;
  if (r) {
    for (int j = 1; j < 101; j++) {
      if (f[n][j]) {
        con(i, f, j, r - 1);
      }
    }
  }
}

int main() {
  for (int n, m; cin >> n >> m, n | m;) {
    bool f[101][101] = {{}};
    while (m--) {
      int a, b;
      cin >> a >> b;
      f[a][b] = f[b][a] = true;
    }
    bool inv[101] = {};
    con(inv, f, 1, 2);
    cout << count(inv + 2, inv + n + 1, true) << endl;
  }
  return 0;
}
Problem p00468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m;
  int in[10010][2];
  bool a[10010];
  bool b[10010];

  while (cin >> n >> m, n | m) {
    for (int i = 0; i < 10010; i++) {
      a[i] = false;
      b[i] = false;
    }

    for (int i = 0; i < m; i++) {
      cin >> in[i][0] >> in[i][1];
    }

    for (int i = 0; i < m; i++) {
      if (in[i][0] == 1) {
        a[in[i][1]] = true;
      } else if (in[i][1] == 1) {
        a[in[i][0]] = true;
      }
    }

    for (int i = 0; i <= n; i++) {
      if (a[i]) {
        b[i] = true;
        for (int j = 0; j < m; j++) {
          if (in[j][0] == i) {
            b[in[j][1]] = true;
          } else if (in[j][1] == i) {
            b[in[j][0]] = true;
          }
        }
      }
    }

    int ans = 0;
    for (int i = 2; i <= n; i++) {
      if (b[i]) {
        ans++;
      }
    }

    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, m;
  int in[1024][2];
  bool a[1024];
  bool b[1024];

  while (cin >> n >> m, n | m) {
    for (int i = 0; i < 1024; i++) {
      a[i] = false;
      b[i] = false;
    }

    for (int i = 0; i < m; i++) {
      cin >> in[i][0] >> in[i][1];
    }

    for (int i = 0; i < m; i++) {
      if (in[i][0] == 1) {
        a[in[i][1]] = true;
      } else if (in[i][1] == 1) {
        a[in[i][0]] = true;
      }
    }

    for (int i = 0; i < n; i++) {
      if (a[i]) {
        b[i] = true;
        for (int j = 0; j < m; j++) {
          if (in[j][0] == i) {
            b[in[j][1]] = true;
          } else if (in[j][1] == i) {
            b[in[j][0]] = true;
          }
        }
      }
    }

    int ans = 0;
    for (int i = 2; i < n; i++) {
      if (b[i]) {
        ans++;
      }
    }

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n, m;
  while (cin >> n >> m && n && m) {
    if (n == 0 && m == 0)
      break;
    vector<int> answers;
    int flist[2][10000];
    int count = 0;
    vector<int> syoutai;

    int fr[501] = {0}, fr2[501] = {0};

    for (int i = 0; i < m; i++)
      cin >> flist[0][i] >> flist[1][i]; // flist[0][0]=1,flist[0][1]=2;

    for (int i = 0; i < m; i++) {
      if (flist[0][i] == 1) {
        int tomo = flist[1][i];
        fr[tomo] = 1; // frには出席番号で印をつける(一応0スタート
        // syoutai.push_back(flist[1][i]);//1が招待した人を追加
      } else if (flist[1][i] == 1) {
        int tomo = flist[0][i];
        fr[tomo] = 1;
      }
    }
    for (int i = 0; i < n + 1; i++) {
      /*if(fr[flist[0][i]]==1){
              int tomo=flist[1][i];
              fr2[tomo]=1;
}*/
      if (fr[i] == 1) { // iはfrにチェックがついている人
        for (int j = 0; j < m; j++) {
          if (flist[0][j] == i) {
            int tomo = flist[1][j];
            fr2[tomo] = 1;
          } else if (flist[1][j] == i) {
            int tomo = flist[0][j];
            fr2[tomo] = 1;
          }
        }
      }
    }
    for (int i = 0; i < n + 1; i++) {
      if (fr[i] == 1 || fr2[i] == 1)
        count++;
    }

    cout << count - 1 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {

  int n, m;
  vector<int> answers;
  while (cin >> n >> m && n && m) {
    if (n == 0 && m == 0)
      break;

    int flist[2][1000];
    int count = 0;
    vector<int> syoutai;

    int fr[501] = {0}, fr2[501] = {0};

    for (int i = 0; i < m; i++)
      cin >> flist[0][i] >> flist[1][i]; // flist[0][0]=1,flist[0][1]=2;

    for (int i = 0; i < m; i++) {
      if (flist[0][i] == 1) {
        int tomo = flist[1][i];
        fr[tomo] = 1; // frには出席番号で印をつける(一応0スタート
        syoutai.push_back(flist[1][i]); // 1が招待した人を追加
      }
    }
    for (int i = 0; i < n + 1; i++) {
      /*if(fr[flist[0][i]]==1){
              int tomo=flist[1][i];
              fr2[tomo]=1;
}*/
      if (fr[i] == 1) {
        for (int j = 0; j < m; j++) {
          if (fr[flist[0][j]] == 1) {
            int tomo = flist[1][j];
            fr2[tomo] = 1;
          }
        }
      }
    }

    for (int i = 0; i < n + 1; i++) {
      if (fr[i] == 1 || fr2[i] == 1)
        count++;
    }
    answers.push_back(count);
  }
  for (int i = 0; i < answers.size(); i++)
    cout << answers[i] << endl;
  return 0;
}
Problem p00468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define INF 1e+8

using namespace std;

int fr[11101];
int cnt, temp, temp1, temp2;
int n, m;
int a[11100], b[11100];
int main(void) {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    cnt = 0;
    REP(i, 11000) {
      fr[i] = 0;
      a[i] = 0;
      b[i] = 0;
    }
    REP(i, m) {
      cin >> a[i] >> b[i];
      if (a[i] > b[i]) {
        temp = a[i];
        a[i] = b[i];
        b[i] = temp;
      }
    }
    REP(i, m) {
      REP(j, m - 1) {
        if (a[i] == 1 && a[j] > a[i]) {
          temp1 = a[i];
          a[i] = a[j];
          a[j] = temp1;
          temp2 = b[i];
          b[i] = b[j];
          b[j] = temp2;
        }
      }
    }
    /*REP(i,m){
        cout<<a[i]<<" "<<b[i]<<endl;
    }*/
    REP(i, m) {
      if (a[i] == 1) {
        fr[a[i]] = 1;
        fr[b[i]] = 1;
      }
      if (fr[a[i]] == 1 && fr[b[i]] == 0) {
        fr[b[i]] = 2;
      }
      if (fr[a[i]] == 0 && fr[b[i]] == 1) {
        fr[a[i]] = 2;
      }
    }
    FOR(i, 2, m) {
      if (fr[i]) {
        cnt++;
        // printf("%d\\n",i);
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define INF 1e+8

using namespace std;

int fr[550];
int cnt, temp, temp1, temp2;
int n, m;
int a[550], b[550];
int main(void) {
  while (1) {
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    cnt = 0;
    REP(i, 550) {
      fr[i] = 0;
      a[i] = 0;
      b[i] = 0;
    }
    cin >> n >> m;
    if (n == 0 && m == 0)
      break;
    REP(i, m) {
      cin >> a[i] >> b[i];
      if (a[i] > b[i]) {
        temp = a[i];
        a[i] = b[i];
        b[i] = temp;
      }
    }
    REP(i, m) {
      REP(j, m - 1) {
        if (a[i] == 1 && a[j] > a[i]) {
          temp1 = a[i];
          a[i] = a[j];
          a[j] = temp1;
          temp2 = b[i];
          b[i] = b[j];
          b[j] = temp2;
        }
      }
    }
    /*REP(i,m){
        cout<<a[i]<<" "<<b[i]<<endl;
    }*/
    /*REP(i,m){
    if(a[i]==1){
            fr[a[i]]=1;
            fr[b[i]]=1;
        }
        if(fr[a[i]]==1&&fr[b[i]]==0){
            fr[b[i]]=2;
        }
        if(fr[a[i]]==0&&fr[b[i]]==1){
            fr[a[i]]=2;
        }
    }*/
    FOR(i, 2, m) {
      if (fr[i]) {
        cnt++;
        // printf("%d\\n",i);
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00468 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main() {
  vector<int> P[500];
  bool S[500];
  int n, m, a, b;
  while (scanf("%d %d", &n, &m), n) {
    for (int i = 0; i < 500; i++)
      P[i].clear(), S[i] = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d %d", &a, &b);
      P[a - 1].push_back(b - 1);
      P[b - 1].push_back(a - 1);
    }
    for (int i = 0; i < P[0].size(); i++) {
      S[P[0][i]] = true;
      for (int j = 0; j < P[P[0][i]].size(); j++) {
        S[P[P[0][i]][j]] = true;
      }
    }
    int num = 0;
    for (int i = 1; i < n; i++) {
      if (S[i])
        num++;
    }
    printf("%d\\n", num);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <utility>
using namespace std;
typedef pair<int, int> P;
#define inf (1 << 27)
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, m, s[500];
  P list[1000];
  while (scanf("%d %d", &n, &m), n) {
    fill(s, s + 500, inf);
    s[0] = 0;
    rep(i, m) {
      scanf("%d %d", &list[i].first, &list[i].second);
      list[i].first--;
      list[i].second--;
    }
    rep(i, m) rep(j, m) {
      if (s[list[j].first] > s[list[j].second])
        s[list[j].first] = s[list[i].second] + 1;
      else if (s[list[j].first] < s[list[j].second])
        s[list[j].second] = s[list[j].first] + 1;
    }
    int num = 0;
    rep(i, n) if (1 <= s[i] && s[i] <= 2) num++;
    printf("%d\\n", num);
  }
}
Problem p00468 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  int n, m;
  bool a[500][500];
  while (cin >> n && n != 0) {
    cin >> m;
    for (int i = 0; i < n; i++)
      fill(a[i], a[i] + n, false);
    set<int> d, f;
    for (int i = 0; i < m; i++) {
      int b, c;
      cin >> b >> c;
      if (b > c)
        swap(b, c);
      b--;
      c--;
      a[b][c] = true;
      a[c][b] = true;
      if (b == 0) {
        f.insert(c);
        d.insert(c);
      }
    }
    set<int>::iterator it = f.begin();
    while (it != f.end()) {
      for (int i = 1; i < n; i++) {
        if (a[(*it)][i]) {
          d.insert(i);
        }
      }
      it++;
    }
    cout << d.size() << endl;
  }
}

Error: 0

Fixed submission:

#include <bits //stdc++.h>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    if (a == 0 && b == 0)
      break;
    int c[a][2];
    int d[a];
    int k[a + 1000000];
    int e = 0, f = 0;
    for (int i = 0; i < b; i++) {
      int n, l;
      cin >> n >> l;
      c[i][0] = n;
      c[i][1] = l;
      ;
      if (c[i][0] == 1) {
        d[e] = c[i][1];
        k[e] = c[i][1];
        e++;
      } else if (c[i][1] == 1) {
        d[e] = c[i][0];
        k[e] = c[i][0];
        e++;
      }
    }
    for (int i = 0; i < b; i++) {
      for (int j = 0; j < e; j++) {
        int g = 0;
        if (c[i][0] == d[j] && c[i][1] != 1) {
          for (int z = 0; z < e; z++) {
            if (c[i][1] == d[z])
              g++;
          }
          if (g == 0) {
            k[e] = c[i][1];
            e++;
          }
        } else if (c[i][1] == d[j] && c[i][0] != 1) {
          for (int z = 0; z < e; z++) {
            if (c[i][0] == d[z])
              g++;
          }
          if (g == 0) {
            k[e] = c[i][0];
            e++;
          }
        }
      }
    }
    int l = e;
    int m[e];
    for (int i = 0; i < e; i++)
      m[i] = 0;
    for (int i = 0; i < e; i++) {
      for (int j = i + 1; j < e; j++) {
        if (k[i] == k[j] && m[i] == 0) {
          m[j] = 1;
          l--;
        }
      }
    }
    cout << l << endl;
  }
}