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

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  while (1) {
    int a = -1, b;
    int dt[101] = {0};
    while (cin >> a >> b && a || b) {
      dt[a]++;
      dt[b]++;
    }
    if (a == -1)
      return 0;
    bool flg = true;
    int sum = 0;
    if (dt[1] % 2 == 0 || dt[2] % 2 == 0)
      flg = false;
    loop(i, 3, 101) if (dt[i] && dt[i] % 2 == 1) {
      flg = false;
      break;
    }
    cout << ((flg) ? "OK" : "NG") << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  while (1) {
    int a = -1, b;
    int dt[101] = {0};
    while (cin >> a >> b, a || b) {
      dt[a]++;
      dt[b]++;
    }
    if (a == -1)
      return 0;
    bool flg = true;
    int sum = 0;
    if (dt[1] % 2 == 0 || dt[2] % 2 == 0)
      flg = false;
    loop(i, 1, 101) if (dt[i] && dt[i] % 2 != 1) flg = false;
    cout << ((flg) ? "OK" : "NG") << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

struct Graph {
  int n;
  struct edge {
    int src, dst, rev;
  };
  vector<vector<edge>> adj;
  Graph() : n(0) {}

  void addEdge(int src, int dst) {
    n = max(n, max(src, dst) + 1);
    if (adj.size() < n)
      adj.resize(n);
    adj[src].push_back({src, dst, (int)adj[dst].size()});
    adj[dst].push_back({dst, src, (int)adj[src].size() - 1});
  }

  bool eulerianPath() {
    int m = 0, s = -1;
    if (adj[0].size() % 2 == 0 || adj[1].size() % 2 == 0)
      return false;
    for (int u = 2; u < n; ++u) {
      if (adj[u].size() % 2 == 1)
        return false;
      ;
    }
    return true;
  }
};

int main() {
  int a, b;
  while (cin >> a >> b) {
    Graph g;
    while (1) {
      g.addEdge(a - 1, b - 1);
      if (cin >> a >> b, a)
        continue;
      break;
    }
    cout << ((g.eulerianPath()) ? "OK" : "NG") << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
             e.src != f.src ? e.src < f.src
                            : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void visit(const Graph &g, vector<vector<int>> &adj, int s, vector<int> &path) {
  for (auto &&e : g[s])
    if (adj[e.src][e.dst]) {
      --adj[e.src][e.dst];
      --adj[e.dst][e.src];
      visit(g, adj, e.dst, path);
    }
  path.push_back(s);
}
bool eulerPath(const Graph &g, int s, vector<int> &path) {
  int n = g.size();
  int odd = 0, m = 0;
  for (int i = 0; i < n; ++i) {
    if (g[i].size() % 2 == 1)
      ++odd;
    m += g[i].size();
  }
  m /= 2;
  if (odd == 0 || (odd == 2 && g[s].size() % 2 == 0)) {
    vector<vector<int>> adj(n, vector<int>(n));
    for (int u = 0; u < n; ++u) {
      for (auto &&e : g[u])
        ++adj[e.src][e.dst];
    }
    path.clear();
    visit(g, adj, s, path);
    reverse(begin(path), end(path));
    return path.size() == m + 1;
  }
  return false;
}

int main() {
  int a, b, m = 0;
  Graph G(100);
  while (cin >> a >> b) {
    do {
      m = max({m, a, b});
      --a;
      --b;
      G[a].push_back({a, b, 1});
      G[b].push_back({b, a, 1});
    } while (cin >> a >> b && a != 0);
    G.resize(m);
    vector<int> path;
    cout << ((!eulerPath(G, 0, path)) ? "OK" : "NG") << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int judge(vector<int> &a, int k) {
  for (int i = 2; i < k; ++i) {
    if (a[i] % 2 == 1) {
      return 1;
    }
  }
  return 0;
}
int main() {
  vector<int> a;
  a.reserve(100);
  int aa, bb;
  while (cin >> aa >> bb) {
    if (aa != 0 && bb != 0) {
      if (max(aa, bb) > a.size())
        a.resize(max(aa, bb), 0);
      a[aa - 1] += 1;
      a[bb - 1] += 1;
    } else {
      if (a[0] % 2 == 1 && a[1] % 2 == 1 && judge(a, a.size()) == 0)
        printf("%s\\n", "OK");
      else
        printf("%s\\n", "NG");
      a.clear();
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int judge(vector<int> &a, int k) {
  for (int i = 2; i < k; ++i) {
    if (a[i] % 2 == 1) {
      return 1;
      break;
    }
  }
  return 0;
}
int main() {
  vector<int> a;
  int aa, bb;
  while (1) {
    int size = 0, largest = 0;
    a.reserve(100);
    while (cin >> aa && cin >> bb && aa != 0 && bb != 0)
      largest = max(aa, max(bb, largest));
    a.resize(largest);
    for (int i = 0; i < largest; ++i)
      a[i] = count(a.begin(), a.end(), i + 1);
    if (a[0] % 2 == 1 && a[1] % 2 == 1 && judge(a, a.size()) == 0)
      printf("%s\\n", "OK");
    else
      printf("%s\\n", "NG");
    a.clear();
  }
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

// Eulerian Path
#include <iostream>
using namespace std;

int node[200]; // node[i] expresses num of node from i
int a, b;

void initialize() {
  for (int i = 0; i < 200; i++) {
    node[i] = 0;
  }
}

bool answer() {
  if (node[1] % 2 == 0 || node[2] % 2 == 0)
    return false;
  for (int i = 3; i < 200; i++) {
    if (node[i] % 2 == 1)
      return false;
  }
  return true;
}

int main() {
  initialize();
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      if (answer()) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
      initialize();
    } else {
      node[a]++;
      node[b]++;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int edge[100][100];
int a, b;
int now;

void initialize() {
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      edge[i][j] = 0;
    }
  }
  now = 1;
}

bool isEmpty() {
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j < 100; j++) {
      if (edge[i][j] > 0)
        return false;
    }
  }
  return true;
}

bool answer(int now) {
  if (now == 2 && isEmpty())
    return true;
  for (int i = 0; i < 100; i++) {
    if (edge[now][i] > 0) {
      edge[now][i]--;
      edge[i][now]--;
      if (answer(i))
        return true;
      edge[now][i]++;
      edge[i][now]++;
    }
  }

  return false;
}

int main() {
  initialize();
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      if (answer(now)) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
      initialize();
    } else {
      edge[a][b]++;
      edge[b][a]++;
    }
  }

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

#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

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

      memset(c, 0, sizeof(c));

    } else {
      c[a]++;
      c[b]++;
    }
  }

  return 0;
}

Error: -6
dbbb49c0-5443-45eb-a972-cfea76aec5e6.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00086/C++/s355585081.cpp:25: Euler::Euler(int): Assertion `false' failed.


Fixed submission:

#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

// ????????????????????????????????????
class Euler {
#define MAX_V 101

private:
  const int INF = 1e9 + 10;
  struct Edge {
    int to;
    Edge(int to) : to(to) {}
  };

  int V;
  vector<Edge> G[MAX_V];

public:
  Euler(int V) : V(V) {
    if (V >= MAX_V) {
      assert(false);
    }
  }

  void AddEdge(int from, int to) { G[from].push_back(Edge(to)); }

  bool Solve(int s, int t) {
    if (!(G[s].size() % 2)) {
      return false;
    }
    if (!(G[t].size() % 2)) {
      return false;
    }

    for (int i = 0; i < V; i++) {
      if (i == s || i == t) {
        continue;
      }
      if (G[i].size() % 2) {
        return false;
      }
    }

    return true;
  }

  void Clear() {
    for (int i = 0; i < V; i++) {
      G[i].clear();
    }
  }
};

int main() {
  Euler euler(101);
  while (true) {
    int a, b;
    if (cin.eof()) {
      break;
    }
    cin >> a >> b;

    if (a + b == 0) {
      if (euler.Solve(1, 2)) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
      euler.Clear();
    } else {
      euler.AddEdge(a, b);
      euler.AddEdge(b, a);
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  int a[100] = {};
  int x, y;
  while (cin >> x >> y) {
    if (x && y) {
      a[x - 1]++;
      a[y - 1]++;
    } else {
      bool ans(true);
      for (int i = 0; i < 100; i++) {
        if (i == 0 || i == 1) {
          if (a[i] % 2 != 1) {
            ans = false;
          }
        } else {
          if (a[i] % 2 != 0)
            ans = false;
        }
        if (!ans)
          break;
      }
      if (ans)
        cout << "OK" << endl;
      else
        cout << "NG" << endl;
      REP(i, 100) a[i] = 0;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() {
  for (;;) {
    int a[100] = {};
    for (;;) {
      int x, y;
      cin >> x >> y;
      if (x == 0 && y == 0) {
        break;
      }
      a[x - 1]++;
      a[y - 1]++;
    }

    bool ans(true);
    for (int i = 0; i < 100; i++) {
      if (i == 0 || i == 1) {
        if (a[i] != 1) {
          ans = false;
        }
      } else {
        if (a[i] % 2 != 0)
          ans = false;
      }
      if (!ans)
        break;
    }

    if (ans)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int a, b;
  while (cin >> a >> b) {
    vi num(105, 0);
    num[a]++;
    num[b]++;
    while (a + b > 0) {
      cin >> a >> b;
      num[a]++;
      num[b]++;
    }
    bool ans = true;
    if (num[1] % 2 == 0 || num[2] % 2 == 0) {
      cout << "NG" << endl;
      ans = false;
      continue;
    }
    loop(i, 3, 105) if (num[i] % 2) {
      cout << "NG" << endl;
      ans = false;
      break;
    }
    if (ans)
      cout << "OK" << endl;
  }
}

Error: -6
double free or corruption (out)


Fixed submission:


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int a, b;
  while (cin >> a >> b) {
    vi num(1000, 0);
    num[a - 1]++;
    num[b - 1]++;
    while (a + b > 0) {
      cin >> a >> b;
      num[a - 1]++;
      num[b - 1]++;
    }
    bool ans = true;
    if (num[0] % 2 == 0 || num[1] % 2 == 0) {
      cout << "NG" << endl;
      ans = false;
    }
    loop(i, 2, 1000) if (num[i] % 2) {
      cout << "NG" << endl;
      ans = false;
      break;
    }
    if (ans)
      cout << "OK" << endl;
  }
}
Problem p00086 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  map<int, int> deg;

  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      bool f = true;
      for (auto p : deg) {
        if (p.first < 2 && ~p.second & 1)
          f = false;
        if (p.first >= 2 && p.second & 1)
          f = false;
      }
      cout << (f ? "OK" : "NG") << endl;
      deg.clear();
      continue;
    }

    a--;
    b--;
    deg[a]++;
    deg[b]++;
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int a, b;
  int n;
  int deg[200] = {};

  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      bool f = true;
      for (int i = 0; i < n; ++i) {
        if (deg[i] & 1 && i < 2 || deg[i] >= 3)
          continue;
        f = false;
        deg[i] = 0;
      }
      cout << (f ? "OK" : "NG") << endl;
    }

    n = max({n, a, b});
    a--;
    b--;
    deg[a]++;
    deg[b]++;
  }
}
Problem p00086 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
  while (1) {
    vector<int> G[100];
    int a, b;
    while (1) {
      if (!(cin >> a >> b)) {
        return 0;
      }
      if (a == 0 && b == 0) {
        break;
      }
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) {
      int c = 0;
      for (int i = 0; i < 100; i++) {
        if (G[i].size() % 2 == 1) {
          c++;
        }
      }
      if (c == 2) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
  while (1) {
    vector<int> G[100];
    int a, b;
    while (1) {
      if (!cin >> a >> b) {
        return 0;
      }
      if (a == 0 && b == 0) {
        break;
      }
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) {
      int c = 0;
      for (int i = 0; i < 100; i++) {
        if (G[i].size() % 2 == 1) {
          c++;
        }
      }
      if (c == 2) {
        cout << "OK" << endl;
      } else {
        cout << "NG" << endl;
      }
    } else {
      cout << "NG" << endl;
    }
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = n - 1; i >= (0); i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define OUT(x) cout << #x << " = " << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int deg[110];

void init(void) { rep(i, 110) deg[i] = 0; }

int main(void) {
  int a, b;
  while (cin >> a >> b) {
    if (a == 0 && b == 0) {
      bool flag = true;
      reps(i, 3, 110) {
        if (deg[i] % 2)
          flag = false;
      }
      if (deg[1] % 2 == 0)
        flag = false;
      if (deg[2] % 2 == 0)
        flag = false;
      if (flag)
        printf("OK\\n");
      else
        printf("NG\\n");
      init();
    } else {
      deg[a]++, deg[b]++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = n - 1; i >= (0); i--)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define OUT(x) cout << #x << " = " << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int deg[110];

void init(void) { rep(i, 110) deg[i] = 0; }

int main(void) {
  while (1) {
    init();
    while (1) {
      int a, b;
      cin >> a >> b;
      if (a == 0 && b == 0)
        break;
      deg[a]++, deg[b]++;
    }
    bool flag = true;
    reps(i, 3, 110) {
      if (deg[i] % 2)
        flag = false;
    }
    if (deg[1] % 2 == 0)
      flag = false;
    if (deg[2] % 2 == 0)
      flag = false;
    if (flag)
      printf("OK\\n");
    else
      printf("NG\\n");
  }
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  while (1) {
    int a, b;
    int G[101] = {0};
    while (1) {
      if (scanf("%d%d", &a, &b) < 2)
        return 0;
      if (a == 0)
        break;
      G[b]++, G[a]++;
    }
    bool flag = true;
    if (G[1] % 2 != 1 || G[2] % 2 != 1)
      flag = false;
    for (int i = 3; i <= 100; i++) {
      if (G[i] % 2 == 1) {
        flag = false;
        break;
      }
    }

    if (flag)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  while (1) {
    int a, b;
    int mx = 0;
    int G[101] = {0};
    while (cin >> a >> b, a + b) {
      if (cin.eof())
        return 0;
      G[b]++, G[a]++;
      mx = max(mx, max(a, b));
    }
    bool flag = true;
    if (G[1] % 2 != 1 || G[2] % 2 != 1)
      flag = false;
    for (int i = 3; i <= mx; i++) {
      if (G[i] % 2 == 1) {
        flag = false;
        break;
      }
    }

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

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

  while (1) {
    int a, b, d[101] = {0};

    while (1) {
      if (scanf("%d%d", &a, &b) < 2)
        return 0;
      if (a == 0)
        break;
      d[a]++;
      d[b]++;
    }
    int f = 1;
    if (!(d[1] % 2 == 1 && d[2] % 2 == 1))
      f = 0;
    for (int i = 3; f == 1 && i <= 100; i++) {
      if (d[i] % 2 == 1)
        f = 0;
    }
    if (f == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, d[100];

  while (1) {
    fill(d, d + 100, 0);
    while (cin >> a >> b, a + b) {
      if (cin.eof())
        goto END;
      d[a]++;
      d[b]++;
    }
    int f = 1;
    if (!(d[1] % 2 == 1 && d[2] % 2 == 1))
      f = 0;
    for (int i = 3; i < 100; i++) {
      if (d[i] % 2 == 1) {
        f = 0;
        break;
      }
    }
    if (f == 1)
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
END:;
  return 0;
}
Problem p00086 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int d[100] = {0};
    --a;
    --b;
    ++d[a], ++d[b];

    while (cin >> a >> b, a || b) {
      --a;
      --b;
      ++d[a], ++d[b];
    }
    bool Flag = false;
    if (d[0] % 2 == 0 || d[1] % 2 == 0)
      Flag = true;

    for (int i = 2; i < 100; i++) {
      if (d[i] % 2)
        Flag = true;
    }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> V;
int cnt[100][100], edge;
void add(int a, int b) {
  --a;
  --b;
  if (find(V[a].begin(), V[a].end(), b) == V[a].end())
    V[a].push_back(b);

  ++cnt[a][b];

  if (find(V[b].begin(), V[b].end(), a) == V[b].end())
    V[b].push_back(a);

  ++cnt[b][a];
}
bool dfs(int atnum, int n) {
  if (atnum == 1 && n == edge)
    return true;
  bool Flag = false;
  for (int i = 0; i < V[atnum].size(); ++i) {
    int to = V[atnum][i], from = atnum;
    if (cnt[to][from] <= 0)
      continue;
    --cnt[to][from], --cnt[from][to];
    Flag |= dfs(to, n + 1);
    ++cnt[to][from], ++cnt[from][to];
  }
  return Flag;
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    edge = 1;
    V.clear();
    V.resize(100);
    fill(cnt[0], cnt[0] + 10000, 0);
    add(a, b);
    while (cin >> a >> b, a || b)
      add(a, b), ++edge;

    if (dfs(0, 0))
      cout << "OK" << endl;
    else
      cout << "NG" << endl;
  }
}
Problem p00086 (C++) — buggy submission, verdict: Runtime Error

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

int AdjM[51] = {0};

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int s, t;
  while (cin >> s >> t) {
    if (s != 0) {
      AdjM[s - 1] += 1;
      AdjM[t - 1] += 1;
    } else {
      AdjM[0] += 1;
      AdjM[1] += 1;

      string output = "OK";

      for (int i = 0; i < 51; ++i) {
        if (AdjM[i] % 2 != 0) {
          output = "NG";
          break;
        }
      }

      cout << output << "\\n";

      Fill(AdjM, 0);
    }
  }
}

Error: 0

Fixed submission:

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

int AdjM[51][51] = {0};

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int s, t;
  while (cin >> s >> t) {
    if (s != 0) {
      AdjM[s - 1][t - 1] += 1;
      AdjM[t - 1][s - 1] += 1;
    } else {
      AdjM[0][1] += 1;
      AdjM[1][0] += 1;

      /*
      for(int i=0;i<51;++i){
          for(int j=0;j<51;++j){
              if(j!=50){
                  cout<<AdjM[i][j]<<" ";
              }
              else if(j==50){
                  cout<<AdjM[i][j]<<"\\n";
              }
          }
      }
      */
      string output = "OK";
      int sum = 0;

      for (int i = 0; i < 51; ++i) {
        for (int j = 0; j < 51; ++j) {
          sum += AdjM[i][j];
        }
        if (sum % 2 != 0) {
          sum = 0;
          output = "NG";
          break;
        }
        sum = 0;
      }

      cout << output << "\\n";

      Fill(AdjM, 0);
    }
  }
}