Problem p03575 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer {
void print(vector<int> v) {
  rep(i, v.size()) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void print(vector<vector<int>> vv) {
  rep(i, vv.size()) {
    rep(j, vv[i].size()) {
      if (j)
        cout << " ";
      cout << vv[i][j];
    }
    cout << endl;
  }
}

void print(pair<int, int> p) {
  cout << "(" << p.first << ", " << p.second << ")" << endl;
}
}; // namespace Printer

//--global--//

//----------//

int main(int argc, const char *argv[]) {
  // 提出時、消す----//
  //--------------//

  int n, m;
  cin >> n >> m;
  vector<int> used(n);
  vector<vector<int>> e(n);
  vector<pair<int, int>> inpE(n);
  fill(ALL(used), 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
    inpE[i] = make_pair(a, b);
  }

  int ans = 0;
  rep(i, m) {
    // cout << "----" << i << "----" << endl;
    // Printer::print(inpE[i]);
    fill(ALL(used), 0);
    queue<int> q;
    q.push(0);
    used[0] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      // cout << u << endl;
      rep(j, e[u].size()) {
        int v = e[u][j];
        if (used[v] == 0) {
          if (!((inpE[i].first == u && inpE[i].second == v) ||
                (inpE[i].first == v && inpE[i].second == u))) {
            q.push(v);
            used[v] = 1;
          }
        }
      }
    }
    bool ok = true;
    rep(j, n) {
      if (used[j] == 0)
        ok = false;
    }
    if (!ok) {
      ans++;
      // cout << "+" << endl;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer {
void print(vector<int> v) {
  rep(i, v.size()) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void print(vector<vector<int>> vv) {
  rep(i, vv.size()) {
    rep(j, vv[i].size()) {
      if (j)
        cout << " ";
      cout << vv[i][j];
    }
    cout << endl;
  }
}

void print(pair<int, int> p) {
  cout << "(" << p.first << ", " << p.second << ")" << endl;
}
}; // namespace Printer

//--global--//

//----------//

int main(int argc, const char *argv[]) {
  // 提出時、消す----//
  //--------------//

  int n, m;
  cin >> n >> m;
  vector<int> used(n);
  vector<vector<int>> e(n);
  vector<pair<int, int>> inpE(m);
  fill(ALL(used), 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
    inpE[i] = make_pair(a, b);
  }

  int ans = 0;
  rep(i, m) {
    // cout << "----" << i << "----" << endl;
    // Printer::print(inpE[i]);
    fill(ALL(used), 0);
    queue<int> q;
    q.push(0);
    used[0] = 1;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      // cout << u << endl;
      rep(j, e[u].size()) {
        int v = e[u][j];
        if (used[v] == 0) {
          if (!((inpE[i].first == u && inpE[i].second == v) ||
                (inpE[i].first == v && inpE[i].second == u))) {
            q.push(v);
            used[v] = 1;
          }
        }
      }
    }
    bool ok = true;
    rep(j, n) {
      if (used[j] == 0)
        ok = false;
    }
    if (!ok) {
      ans++;
      // cout << "+" << endl;
    }
  }

  cout << ans << endl;

  return 0;
}