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

#include <stdio.h>

int main(void) {
  int dat[1000] = {0};
  while (1) {
    int a = 0, b = 0;
    int res = scanf("%d %d", &a, &b);
    if (res != 2) {
      if (res == 0) {
        break;
      }
      if (res == -1) {
        break;
      }
      int violate = *(int *)0;
      *(int *)0 = 913;
    }
    if (!a || !b) {
      int cnt = 0;
      for (int i = 1; i < 1000; i++) {
        if (dat[i] % 2 == 1)
          cnt++;
        dat[i] = 0;
      }
      if ((cnt == 2 && dat[1] == dat[2])) {
        puts("OK");
      } else {
        puts("NG");
      }
      continue;
    }
    dat[a] = 1 - dat[a];
    dat[b] = 1 - dat[b];
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int dat[1000] = {0};
  while (1) {
    int a = 0, b = 0;
    int res = scanf("%d%d", &a, &b);
    if (res != 2) {
      if (res == 0) {
        break;
      }
      if (res == 1) {
        break;
      }
      int violate = *(int *)0;
      *(int *)0 = 913;
    }
    if (!a || !b) {
      int cnt = 0;
      for (int i = 1; i < 1000; i++) {
        if (dat[i] % 2 == 1)
          cnt++;
        dat[i] = 0;
      }
      if (cnt == 0 || cnt == 2) {
        puts("OK");
      } else {
        puts("NG");
      }
      continue;
    }
    dat[a] = 1 - dat[a];
    dat[b] = 1 - dat[b];
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

struct edge {
  int to, cost, num;
};

vector<edge> G[200];
bool used[100000];
int sz;

bool ok;

void dfs(int s, int d) {
  if (d == sz) {
    ok = true;
    return;
  } else if (ok)
    return;
  for (int i = 0; i < G[s].size(); i++) {
    edge e = G[s][i];
    if (!used[G[s][i].num]) {
      used[G[s][i].num] = true;
      dfs(G[s][i].to, d + 1);
      used[G[s][i].num] = false;
    }
  }
}

int main() {
  while (1) {
    ok = false;
    fill(used, used + 100000, false);
    int from, to;
    sz = 0;
    while (cin >> from >> to && !(from == 0 && to == 0)) {
      edge e;
      e.to = to;
      e.num = sz;
      G[from].push_back(e);
      e.to = from;
      G[to].push_back(e);
      sz++;
    }
    if (cin.eof())
      break;

    if (G[1].size() % 2 == 1 && G[2].size() % 2 == 1) {
      bool f = false;
      for (int i = 3; i < 101; i++) {
        if (G[i].size() == 0)
          continue;
        else {
          if (G[i].size() % 2) {
            cout << "NG" << endl;
            f = true;
            break;
          }
        }
      }
      if (!f) {
        cout << "OK" << endl;
      }
    } else
      cout << "NG" << endl;

    //		dfs(1,0);
    // if(ok)
    //	cout<<"OK"<<endl;
    // else
    //	cout<<"NG"<<endl;

    for (int i = 0; i < 200; i++)
      G[i].clear();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

struct edge {
  int to, cost, num;
};

vector<edge> G[200];
bool used[100000];
int sz;

bool ok;

void dfs(int s, int d) {
  if (d == sz) {
    ok = true;
    return;
  } else if (ok)
    return;
  for (int i = 0; i < G[s].size(); i++) {
    edge e = G[s][i];
    if (!used[G[s][i].num]) {
      used[G[s][i].num] = true;
      dfs(G[s][i].to, d + 1);
      used[G[s][i].num] = false;
    }
  }
}

int main() {
  while (1) {
    ok = false;
    fill(used, used + 100000, false);
    int from, to;
    sz = 0;
    while (cin >> from >> to && !(from == 0 && to == 0)) {
      edge e;
      e.to = to;
      e.num = sz;
      G[from].push_back(e);
      e.to = from;
      G[to].push_back(e);
      sz++;
    }
    if (cin.eof())
      break;
    dfs(1, 0);
    if (ok)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;

    for (int i = 0; i < 200; i++)
      G[i].clear();
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b;
  int t[102];
  memset(t, 0, sizeof(t));
  while (cin >> a >> b) {
    if (a != 0) {
      t[a]++;
      t[b]++;
    } else {
      if (t[1] % 2 && t[2] % 2) {
        for (int i = 3; i < 101; i++)
          if (t[i] % 2) {
            cout << "NG" << endl;
            goto n;
          }
        cout << "OK" << endl;
      } else
        cout << "NG" << endl;
    n:
      memset(t, 0, sizeof(t));
    }
  }
}

Error: TLE

Fixed submission:

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

int a, b, to = 0;
int t[102][102];

bool dfs(int i) {
  if (i == 2) {
    if (!to)
      return 1;
  }
  for (int j = 0; j < 100; j++) {
    if (t[i][j]) {
      t[i][j]--;
      to--;
      if (dfs(j))
        return 1;
      t[i][j]++;
      to++;
    } else if (t[j][i]) {
      t[j][i]--;
      to--;
      if (dfs(j))
        return 1;
      t[j][i]++;
      to++;
    }
  }
  return 0;
}
int main() {
  memset(t, 0, sizeof(t));
  while (cin >> a >> b) {
    if (a != 0) {
      t[a][b]++;
      to++;
    } else {
      if (dfs(1))
        cout << "OK" << endl;
      else
        cout << "NG" << endl;
      memset(t, 0, sizeof(t));
      to = 0;
    }
  }
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i;
  int p, q;
  while (cin >> p >> q) {
    int a[100];
    memset(a, 0, sizeof(a));
    while (p + q) {
      p--;
      q--;
      a[p]++;
      a[q]++;
      cin >> p >> q;
    }
    if (a[0] % 2 && a[1] % 2) {
      for (i = 2; i < 100; i++) {
        if (a[i] % 2)
          break;
      }
      if (i == 100)
        cout << "OK" << endl;
      else
        cout << "NG" << endl;
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int f(int a[][100], int n, int p, int q) {
  int i;
  if (q == n)
    return p == 1;
  for (i = 0; i < 100; i++) {
    if (p != i) {
      if (a[min(p, i)][max(p, i)]) {
        a[min(p, i)][max(p, i)]--;
        if (f(a, n, i, q + 1))
          return 1;
        a[min(p, i)][max(p, i)]++;
      }
    }
  }
  return 0;
}
int main() {
  int a[100][100], n, p, q;
  while (cin >> p >> q) {
    memset(a, 0, sizeof(a));
    n = 0;
    while (p != 0 || q != 0) {
      p--;
      q--;
      a[min(p, q)][max(p, q)]++;
      n++;
      cin >> p >> q;
    }
    if (f(a, n, 0, 0))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (1) {
    a = -1;
    int data[100] = {0};
    while (cin >> a >> b && a || b) {
      a--;
      b--;
      data[a]++;
      data[b]++;
    }
    if (a == -1)
      return 0;

    bool flag = false;
    /*?????????????????´??????????\\???°???????????????????????§????????????*/
    if (data[0] % 2 == 0 || data[1] % 2 == 0)
      flag = true;
    for (int i = 2; i < 100; i++) {
      /*??????????????¨??´????????\\???????\\???°??????????????°*/
      if (data[i] % 2 == 1 && data[i]) {
        flag = true;
      }
    }
    cout << (flag ? "NG" : "OK") << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;

#define MAX_N 101

void q86() {
  for (;;) {

    int start = 1;
    int goal = 2;
    int haveLine[MAX_N];
    memset(haveLine, 0, sizeof(haveLine));
    for (;;) {
      int s, t;
      cin >> s >> t;
      if (!s)
        break;
      haveLine[s]++;
      haveLine[t]++;
    }
    bool flag = true;
    if (haveLine[start] & 1 == 0 || haveLine[goal] & 1 == 0) {
      flag = false;
    }
    for (int i = 3; i < MAX_N; i++) {
      if (haveLine[i] & 1 == 1)
        flag = false;
    }

    cout << (flag ? "OK" : "NG") << endl;
  }
}

int main() {
  q86();
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

const int nmax = 101;

bool judge(int area[nmax][nmax]) {
  int r[nmax];
  for (int i = 1; i < nmax; i++) {
    int count = 0;
    for (int j = 1; j < nmax; j++) {
      count += area[i][j];
    }
    r[i] = count;
  }
  if (r[1] % 2 == 0 || r[2] % 2 == 0)
    return false;
  for (int i = 3; i < nmax; i++) {
    if (r[i] % 2)
      return false;
  }
  return true;
}

int main() {
  int area[nmax][nmax];
  int a, b;
  while (cin >> a >> b) {
    for (int i = 1; i < nmax; i++) {
      for (int j = 1; j < nmax; j++) {
        area[i][j] = 0;
      }
    }
    do {
      if (a == 0 && b == 0)
        break;
      area[a][b]++;
      area[b][a]++;
    } while (cin >> a >> b);
    if (judge(area))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int nmax = 101;

int move(int area[nmax][nmax], int i, int count) {
  int num = 0;
  if (i == 2 && count == 0) {
    return 1;
  } else if (count == 0) {
    return 0;
  }
  for (int j = 1; j < nmax; j++) {
    if (area[i][j]) {
      area[i][j]--;
      area[j][i]--;
      count--;
      num += move(area, j, count);
      count++;
      area[i][j]++;
      area[j][i]++;
    }
  }
  return num;
}

int main() {
  int area[nmax][nmax];
  int a, b;
  while (cin >> a >> b) {
    for (int i = 1; i < nmax; i++) {
      for (int j = 1; j < nmax; j++) {
        area[i][j] = 0;
      }
    }
    int count = 0;
    do {
      if (a == 0 && b == 0)
        break;
      area[a][b]++;
      area[b][a]++;
      count++;
    } while (cin >> a >> b);
    if (move(area, 1, count))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
  short r[101] = {};
  int a, b;
  while (cin >> a >> b) {
    r[a]++;
    r[b]++;
    if (a == 0) {
      bool f = true;
      FOR(i, 1, 101) {
        if (i == 1 || i == 2) {
          if (r[i] % 2 == 0) {
            f = false;
            break;
          }
        } else if (r[i] % 2 == 1) {
          f = false;
          break;
        }
      }

      if (!f) {
        cout << "NG" << endl;
      } else {
        cout << "OK" << endl;
      }
      rep(i, 101) r[i] = 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, k, n) for (int(i) = (k); (i) < (n); ++(i))
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template <class T> using vv = vector<vector<T>>;
typedef deque<int> di;
typedef deque<deque<int>> ddi;

int main() {
  while (1) {
    short r[101] = {};
    while (1) {
      int a, b;
      cin >> a >> b;
      r[a]++;
      r[b]++;
      if (a == 0) {
        bool f = true;
        FOR(i, 3, 101) {
          if (r[i] % 2 == 1) {
            f = false;
            break;
          }
        }
        if (!f) {
          cout << "NG" << endl;
        } else {
          cout << "OK" << endl;
        }
        break;
      }
    }
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

int path[101];
int main(void) {
  int a, b;
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      bool ans =
          all_of(path + 3, path + 100, [=](int n) { return n % 2 == 0; }) &&
          path[1] % 2 == 1 && path[2] % 2 == 1;
      cout << (ans ? "OK" : "NG") << endl;
      memset(path, 0, sizeof(path));
    }
    path[a]++;
    path[b]++;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int main(void) {
  while (true) {
    vector<vector<int>> graph(110);
    int a, b;
    while (cin >> a >> b && a && b) {
      graph[a].push_back(b);
      graph[b].push_back(a);
    }

    bool ans = true;
    for (int i = 3; i < graph.size(); i++) {
      if (graph[i].empty())
        break;
      if ((graph[i].size() % 2) != 0) {
        ans = false;
        break;
      }
    }
    cout << (ans ? "OK" : "NG") << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int cross[101];

  while (!feof(stdin)) {
    for (int i = 0; i < 101; i++) {
      cross[i] = 0;
    }

    while (true) {
      int a, b;
      // if(scanf("%d %d", &a, &b)<=0){return 0;}
      scanf("%d %d", &a, &b);
      if (a == 0) {
        if (feof(stdin)) {
          return 0;
        }
        bool ng = false;
        if (cross[1] % 2 == 1 && cross[2] % 2 == 1) {
          for (int i = 3; i < 101; i++) {
            if (cross[i] % 2 == 1) {
              ng = true;
              break;
            }
          }
        } else {
          ng = true;
        }
        puts(ng ? "NG" : "OK");
        break;
      }
      cross[a]++;
      cross[b]++;
    }
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int cross[101];

  while (true) {
    for (int i = 0; i < 101; i++) {
      cross[i] = 0;
    }

    while (true) {
      int a, b;
      scanf("%d %d", &a, &b);
      if (a == 0) {
        bool ng = false;
        for (int i = 3; i < 101; i++) {
          if (cross[i] % 2 == 1) {
            ng = true;
            break;
          }
        }
        puts(ng ? "NG" : "OK");
        break;
      }
      cross[a]++;
      cross[b]++;
    }
  }
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int main() {

  int a, b;
  while (cin >> a >> b) {
    int p[120] = {0};
    p[a]++;
    p[b]++;
    while (cin >> a >> b, a != 0 || b != 0) {
      p[a]++;
      p[b]++;
    }

    bool f = true;
    for (int i = 3; i < 101; i++) {
      if (p[i] % 2 != 0) {
        f = false;
        break;
      }
    }
    if (f && p[1] % 2 && p[2] % 2)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cctype>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int main() {

  while (1) {
    int p[120] = {0};
    int a, b;
    while (cin >> a >> b, a != 0 || b != 0) {
      p[a]++;
      p[b]++;
    }

    bool f = true;
    for (int i = 3; i < 101; i++) {
      if (p[i] % 2 != 0) {
        f = false;
        break;
      }
    }
    if (f && p[1] % 2 && p[2] % 2)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(void) {

  int n, m;
  while (cin >> n >> m) {
    int graph[105] = {0};
    while (1) {
      graph[n]++;
      graph[m]++;
      cin >> n >> m;
      if (n == 0 && m == 0)
        break;
    }
    bool flag = true;
    if (graph[1] % 2 == 0 || graph[2] % 2 == 0) {
      flag = false;
      cout << "NG" << endl;
    }
    if (flag) {
      for (int i = 3; i < 105; i++) {
        if (graph[i] % 2 == 1) {
          flag = false;
          cout << "NG" << endl;
          break;
        }
      }
    }
    if (flag) {
      cout << "OK" << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

using namespace std;

void cp(int temp[105][105], int graph[105][105]) {
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j < 105; j++) {
      temp[i][j] = graph[i][j];
    }
  }
}

bool ch(int graph[105][105]) {
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j < 105; j++) {
      if (graph[i][j] > 0)
        return false;
    }
  }
  return true;
}

bool ch2(int graph[105][105]) {
  for (int i = 0; i < 105; i++) {
    if (graph[2][i] > 0)
      return false;
  }
  return true;
}

bool Patrol(int now, int graph[105][105]) {
  if (now == 2)
    return ch(graph);
  if (ch2(graph))
    return false;

  for (int i = 0; i < 105; i++) {
    if (graph[now][i] > 0) {
      int temp[105][105];
      cp(temp, graph);
      temp[now][i]--;
      temp[i][now]--;
      int temp_now = i;
      if (Patrol(temp_now, temp) == true) {
        return true;
      }
    }
  }
  return false;
}

int main(void) {

  int n, m;
  while (cin >> n >> m) {
    int graph[105][105] = {0};
    while (1) {
      graph[n][m]++;
      graph[m][n]++;
      cin >> n >> m;
      if (n == 0 && m == 0)
        break;
    }

    if (Patrol(1, graph))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

// I read the chiebukuro's article about Hitohudegaki
// http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1090450460

int main() {

  int from, to, table[101] = {0};
  bool FLG;

  while (scanf("%d %d", &from, &to) != EOF) {
    if (from == 0 && to == 0) {
      if (table[1] % 2 == 1 && table[2] % 2 == 1) {
        FLG = true;
        for (int i = 3; i <= 100; i++) {
          if (table[i] % 2 == 1) {
            FLG = false;
            break;
          }
        }
        if (FLG)
          printf("OK\\n");
        else {
          printf("NG\\n");
        }
      } else {
        printf("NG\\n");
      }
      for (int i = 0; i < 101; i++)
        table[i] = 0;
      continue;
    } else {
      table[from]++;
      table[to]++;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>

using namespace std;

struct Info {
  Info() { current = 0; }

  Info(int arg_current, short map[101][101]) {
    current = arg_current;
    for (int i = 0; i < 101; i++) {
      for (int k = 0; k < 101; k++)
        table[i][k] = map[i][k];
    }
  }
  int current;
  short table[101][101];
};

short map
    [101]
    [101]; //?????????????????????????????¨???????????°<????????°?????¨????????´?????????!!!???>
bool Found;
int start = 1, goal = 2, from, to;
Info tmp;

void recursive(Info tmp) {

  if (tmp.current == 2) {
    //??¨?????????????????£?????????OK
    Found = true;
    for (int i = 1; i <= 100; i++) {
      for (int k = 1; k <= 100; k++) {
        if (tmp.table[i][k] >
            0) { //?°?????????¨???1??¬?????£????????????????????£????????????
          Found = false;
          break;
        }
      }
      if (Found)
        break;
    }
    return; // OK????????????????????????return
  }

  if (Found)
    return;

  for (int k = 1; k <= 100; k++) {
    if (tmp.table[tmp.current][k] > 0) { //??????????????´???
      Info newInfo(k, tmp.table);

      newInfo.table[tmp.current][k]--;
      newInfo.table[k][tmp.current]--;
      recursive(newInfo);
    }
  }
}

void func(int a, int b) {
  for (int i = 1; i <= 100; i++) {
    for (int k = 1; k <= 100; k++) {
      map[i][k] = 0; // i??¨k????????¶????????¬??°????¨??????????????????????
    }
  }

  map[a][b]++;
  map[b][a]++;

  while (true) {
    scanf("%d %d", &from, &to);
    if (from == 0 && to == 0)
      break;

    map[from][to]++;
    map[to][from]++;
  }

  Found = false;

  recursive(Info(1, map));

  if (Found)
    printf("OK\\n");
  else {
    printf("NG\\n");
  }
}

int main() {

  int a, b;

  while (scanf("%d %d", &a, &b) != EOF) {
    func(a, b);
  }

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

#include <iostream>
using namespace std;

#define max(a, b) (a > b ? a : b)
int tx[101];

int main() {
  int a, b, n;
  bool f;
  while (cin >> a >> b) {
    n = 0;
    f = false;
    fill(tx, tx + 101, 0);
    while (a != 0) {
      tx[a]++;
      tx[b]++;
      n = max(n, max(a, b));
      cin >> a >> b;
    }
    if (tx[1] % 2 != 0 && tx[2] % 2 != 0) {
      for (int i = 3; i <= n; i++) {
        if (tx[i] % 2 != 0) {
          f = true;
          break;
        }
      }
    } else {
      f = true;
    }
    if (f) {
      cout << "NG" << endl;
    } else {
      cout << "OK" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define max(a, b) (a > b ? a : b)
int tx[101];

int main() {
  int a, b, n;
  bool f;
  while (true) {
    n = 0;
    f = false;
    fill(tx, tx + 101, 0);
    while (cin >> a >> b && a != 0) {
      tx[a]++;
      tx[b]++;
      n = max(n, max(a, b));
    }
    if (tx[1] % 2 != 0 && tx[2] % 2 != 0) {
      for (int i = 3; i <= n; i++) {
        if (tx[i] % 2 != 0) {
          f = true;
          break;
        }
      }
    } else {
      f = true;
    }
    if (f) {
      cout << "NG" << endl;
    } else {
      cout << "OK" << endl;
    }
  }

  return 0;
}