Problem p00086 (C++)

Buggy submission (status: Runtime Error):
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) FOR(i, 0, n)

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// debug
//-------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
vector<int> intersection[103];

int search() {
  int odd = 0;
  if (intersection[1].size() % 2 != 1 || intersection[2].size() % 2 != 1) {
    return 0;
  }
  FOR(i, 3, 103) {
    if (intersection[i].size() % 2 == 1) {
      debug(i);
      debug(intersection[i].size());
      return 0;
    }
  }
  return 1;
}

void init() {
  REP(i, 103) {
    intersection[i].clear();
    intersection[i].shrink_to_fit();
  }
}

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

  while (1) {
    int s, d;
    cin >> s >> d;
    if (cin.eof())
      break;

    intersection[s].push_back(d);
    intersection[d].push_back(s);

    if (!s && !d) {
      if (search()) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
      init();
    }
  }

  return 0;
}

Fixed submission:
// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORR(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) FOR(i, 0, n)

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// debug
//-------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
vector<int> intersection[103];

int search() {
  int odd = 0;
  if (intersection[1].size() % 2 != 1 || intersection[2].size() % 2 != 1) {
    return 0;
  }
  FOR(i, 3, 103) {
    if (intersection[i].size() % 2 == 1) {
      return 0;
    }
  }
  return 1;
}

void init() {
  REP(i, 103) {
    intersection[i].clear();
    intersection[i].shrink_to_fit();
  }
}

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

  while (1) {
    int s, d;
    cin >> s >> d;
    if (cin.eof())
      break;

    intersection[s].push_back(d);
    intersection[d].push_back(s);

    if (!s && !d) {
      if (search()) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
      init();
    }
  }

  return 0;
}