prithivMLmods/Coder-Stat huggingface dataset:
Problem p03089 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> b(n), a(n);
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int j = 0; j < n; j++) {
    for (int i = n - 1; i >= 0; i--) {
      if (i + 1 == b[i]) {
        a[j] = b[i];
        b.erase(b.begin() + i);
        break;
      }
    }
  }
  if (a[n - 1] != 1)
    cout << -1 << endl;
  else {
    for (int i = n - 1; i >= 0; i--)
      cout << a[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> b(n), a(n);
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int j = 0; j < n; j++) {
    for (int i = b.size() - 1; i >= 0; i--) {
      if (i + 1 == b[i]) {
        a[j] = b[i];
        b.erase(b.begin() + i);
        break;
      }
    }
  }
  if (a[n - 1] != 1)
    cout << -1 << endl;
  else {
    for (int i = n - 1; i >= 0; i--)
      cout << a[i] << endl;
  }
}
Problem p03089 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
  v = vector<T>(n + o);
  for (lli i = o; i < n + o; ++i)
    cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
  for (lli i = o; i < n + o; ++i)
    cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  vector<lli> b;
  cin >> n;
  read_n(b, n, 1);
  b[0] = -1;
  vector<lli> c;
  while (b.size() >= 2) {
    lli j = b.size() - 1;
    for (; j >= 0; --j) {
      if (b[j] == j) {
        b.erase(begin(b) + j);
        c.push_back(j);
        break;
      }
    }
    if (j == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (lli i = c.size() - 1; i >= 0; --i)
    cout << c[i] << '\n';
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
  v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n, size_t o = 0) {
  v = vector<T>(n + o);
  for (lli i = o; i < n + o; ++i)
    cin >> v[i];
}
template <class T> void read_n(T a[], size_t n, size_t o = 0) {
  for (lli i = o; i < n + o; ++i)
    cin >> a[i];
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  vector<lli> b;
  cin >> n;
  read_n(b, n, 1);
  b[0] = -1;
  vector<lli> c;
  while (b.size() >= 2) {
    lli j = b.size() - 1;
    for (; j > 0; --j) {
      if (b[j] == j) {
        b.erase(begin(b) + j);
        c.push_back(j);
        break;
      }
    }
    if (j == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  for (lli i = c.size() - 1; i >= 0; --i)
    cout << c[i] << '\n';
  return 0;
}
Problem p03089 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
b_list = list(map(int, input().split()))

generate_seq = []


def is_ok(b):
    len_b = len(b)
    if len_b == 1 and b[0] == 1:
        generate_seq.append(1)
        return True

    processing = []
    for idx in range(len_b):
        if b[idx] != idx + 1:
            processing.append(False)
        else:
            b_tmp = b[:]
            del b_tmp[idx]
            tmp = is_ok(b_tmp)
            if tmp:
                generate_seq.append(idx + 1)
                return True
    return False


result = is_ok(b_list)
if result:
    print("\n".join(list(map(str, generate_seq))))
else:
    print(-1)


Fixed submission:
N = int(input())
b_list = list(map(int, input().split()))

generate_seq = []


def is_ok(b):
    len_b = len(b)
    if len_b == 1 and b[0] == 1:
        generate_seq.append(1)
        return True

    for idx, val in enumerate(b):
        if idx + 1 < val:
            return False

    processing = []
    for idx in range(len_b):
        if b[idx] != idx + 1:
            processing.append(False)
        else:
            b_tmp = b[:]
            del b_tmp[idx]
            tmp = is_ok(b_tmp)
            if tmp:
                generate_seq.append(idx + 1)
                return True
    return False


result = is_ok(b_list)
if result:
    print("\n".join(list(map(str, generate_seq))))
else:
    print(-1)
Problem p03089 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int Check(vector<int> &b) {

  for (int i = 0; i < b.size(); i++) {
    if (b[i] == i + 1) {
      int temp = b[i];
      if (b.size() == 1) {
        cout << temp << endl;
        return 1;
      } else {
        b.erase(b.begin() + i);
      }
      if (Check(b) == 1) {
        cout << temp << endl;
        return 1;
      }
      b.insert(b.begin() + i, temp);
    }
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    int tmp;

    cin >> tmp;
    b.push_back(tmp);
    if (b[i] > i + 1) {
      cout << "-1";
      return 0;
    }
  }
  if (Check(b) == 0) {
    cout << "-1";
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int Check(vector<int> &b) {

  for (int i = b.size() - 1; i >= 0; i--) {
    if (b[i] == i + 1) {
      int temp = b[i];
      if (b.size() == 1) {
        cout << temp << endl;
        return 1;
      } else {
        b.erase(b.begin() + i);
      }
      if (Check(b) == 1) {
        cout << temp << endl;
        return 1;
      }
      b.insert(b.begin() + i, temp);
    }
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  vector<int> b;
  for (int i = 0; i < n; i++) {
    int tmp;

    cin >> tmp;
    b.push_back(tmp);
    if (b[i] > i + 1) {
      cout << "-1";
      return 0;
    }
  }
  if (Check(b) == 0) {
    cout << "-1";
  }

  return 0;
}
Problem p03089 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

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

  int N;
  cin >> N;
  vector<int> b(N);
  for (auto &x : b)
    cin >> x;

  for (int i = 0; i < N; i++) {
    if (b[i] > i + 1) {
      cout << -1 << endl;
      return 0;
    }
  }

  stack<pair<vector<int>, vector<int>>> st;
  st.emplace(b, vector<int>());
  while (!st.empty()) {
    auto now = st.top();
    st.pop();
    if (now.first.size() == 0) {
      reverse(now.second.begin(), now.second.end());
      for (auto &x : now.second)
        cout << x << endl;
      return 0;
    }
    for (int i = now.first.size() - 1; i >= 0; i--) {
      if (now.first[i] == i + 1) {
        auto newVec1 = now.first;
        newVec1.erase(newVec1.begin() + i);
        auto newVec2 = now.second;
        newVec2.push_back(i + 1);
        st.emplace(newVec1, newVec2);
      }
    }
  }

  cout << -1 << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

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

  int N;
  cin >> N;
  vector<int> b(N);
  for (auto &x : b)
    cin >> x;

  for (int i = 0; i < N; i++) {
    if (b[i] > i + 1) {
      cout << -1 << endl;
      return 0;
    }
  }

  stack<pair<vector<int>, vector<int>>> st;
  st.emplace(b, vector<int>());
  while (!st.empty()) {
    auto now = st.top();
    st.pop();
    if (now.first.size() == 0) {
      reverse(now.second.begin(), now.second.end());
      for (auto &x : now.second)
        cout << x << endl;
      return 0;
    }
    for (int i = 0; i < now.first.size(); i++) {
      if (now.first[i] == i + 1) {
        auto newVec1 = now.first;
        newVec1.erase(newVec1.begin() + i);
        auto newVec2 = now.second;
        newVec2.push_back(i + 1);
        st.emplace(newVec1, newVec2);
      }
    }
  }

  cout << -1 << endl;

  return 0;
}
Problem p03089 (C++)

Buggy submission (status: Time Limit Exceeded):
// Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e2 + 5;
int n, b[N], vis[N], a[N];

bool dfs(int pos, int idx) {
  a[idx] = pos;
  if (idx == n)
    return true;

  int used = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      used++;
    else if (b[i] + used > i)
      return false;
    else if (b[i] + used == i) {
      vis[i] = 1;
      if (dfs(i, idx + 1))
        return true;
      vis[i] = 0;
    }
  }
  return false;
}

bool solve() {
  for (int i = 1; i <= n; i++) {
    if (b[i] == i) {
      vis[i] = 1;
      if (dfs(i, 1))
        return true;
      vis[i] = 0;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen("./input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> b[i];

  bool ok = solve();
  if (!ok)
    cout << -1 << endl;
  else {
    for (int i = n; i >= 1; i--) {
      cout << b[a[i]] << endl;
    }
  }
  return 0;
}


Fixed submission:
// Created by sz
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e2 + 5;
int n, b[N], vis[N], a[N];

bool dfs(int pos, int idx) {
  a[idx] = pos;
  if (idx == n)
    return true;

  int used = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      used++;
    else if (b[i] + used > i)
      return false;
  }
  used = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i])
      used++;
    else if (b[i] + used == i) {
      vis[i] = 1;
      if (dfs(i, idx + 1))
        return true;
      vis[i] = 0;
    }
  }
  return false;
}

bool solve() {
  for (int i = 1; i <= n; i++) {
    if (b[i] == i) {
      vis[i] = 1;
      if (dfs(i, 1))
        return true;
      vis[i] = 0;
    }
  }
  return false;
}

int main() {
#ifdef LOCAL
  freopen("./input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> b[i];

  bool ok = solve();
  if (!ok)
    cout << -1 << endl;
  else {
    for (int i = n; i >= 1; i--) {
      cout << b[a[i]] << endl;
    }
  }
  return 0;
}
Problem p03090 (C++)

Buggy submission (status: Runtime Error):
/**
 * There is a start and there is no end in the space. ---Infinity.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the
 * land. It can be said that this is an final ultimatum from the god to the
 * people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

const int N = 110;

int vis[N];

int main() {

  int n, cnt1 = 0;
  scanf("%d", &n);
  int t = (n + 1) * n / 2;
  if (t & 1) {
    if ((n & 1) == 0) {
      printf("%d\n", n * (n - 2) / 2);
      for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
          if (i + j != n + 1) {
            printf("%d %d \n", i, j);
          }
        }
      }
      return 0;
    } else
      return -1;
  }
  t /= 2;
  for (int i = n; i >= 1 && t; i--) {
    if (t >= i) {
      t -= i;
      vis[i] = 1;
      cnt1++;
    }
  }
  printf("%d\n", cnt1 * (n - cnt1));
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      for (int j = 1; j <= n; j++) {
        if (!vis[j]) {
          printf("%d %d \n", i, j);
        }
      }
    }
  }

  return 0;
}


Fixed submission:
/**
 * There is a start and there is no end in the space. ---Infinity.
 * It ruins and goes though there is also a start in stars. ---Finite.
 * Only the man who has wisdom can read the most foolish one from the history.
 * Fishes living in the sea doesn't know the life in the land.
 * It also ruins and goes if they have wisdom.
 * It funnier that man exceeds the speed of light than fish start living in the
 * land. It can be said that this is an final ultimatum from the god to the
 * people who can fight.
 *
 * Steins;Gate
 */

#include <bits/stdc++.h>

const int N = 110;

int vis[N];

int main() {

  int n, cnt1 = 0;
  scanf("%d", &n);
  int t = (n + 1) * n / 2;
  if (t & 1) {
    if ((n & 1) == 0) {
      printf("%d\n", n * (n - 2) / 2);
      for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
          if (i + j != n + 1) {
            printf("%d %d \n", i, j);
          }
        }
      }
      return 0;
    } else {
      printf("%d \n", (n - 1) * (n - 3) / 2 + n - 1);
      for (int i = 1; i < n; i++) {
        printf("%d %d \n", i, n);
      }
      for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
          if (i + j != n) {
            printf("%d %d \n", i, j);
          }
        }
      }
    }
    return 0;
  }
  t /= 2;
  for (int i = n; i >= 1 && t; i--) {
    if (t >= i) {
      t -= i;
      vis[i] = 1;
      cnt1++;
    }
  }
  printf("%d\n", cnt1 * (n - cnt1));
  for (int i = 1; i <= n; i++) {
    if (vis[i]) {
      for (int j = 1; j <= n; j++) {
        if (!vis[j]) {
          printf("%d %d \n", i, j);
        }
      }
    }
  }

  return 0;
}
Problem p03090 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  int n;
  cin >> n;
  int sum = n;
  vector<vector<int>> flag(100, vector<int>(100, 0));
  vector<int> ans1, ans2;
  if (n % 2 == 0)
    sum++;
  REP(i, 1, n + 1) {
    REP(l, 1, n + 1) {
      if (i != l && flag[i][l] == 0 && i + l != sum) {
        flag[i][l]++;
        flag[l][i]++;
        ans1.pb(i);
        ans2.pb(l);
      }
    }
  }
  cout << ans1.size() << endl;
  REP(i, 0, ans1.size()) { cout << ans1[i] << " " << ans2[i] << endl; }
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for (int i = (l), i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                  'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                  's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main() {
  int n;
  cin >> n;
  int sum = n;
  vector<vector<int>> flag(101, vector<int>(101, 0));
  vector<int> ans1, ans2;
  if (n % 2 == 0)
    sum++;
  REP(i, 1, n + 1) {
    REP(l, 1, n + 1) {
      if (i != l && flag[i][l] == 0 && i + l != sum) {
        flag[i][l]++;
        flag[l][i]++;
        ans1.pb(i);
        ans2.pb(l);
      }
    }
  }
  cout << ans1.size() << endl;
  REP(i, 0, ans1.size()) { cout << ans1[i] << " " << ans2[i] << endl; }
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template <class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1e5, mod = 1e9 + 7;
int n, m, u[maxn + 5], v[maxn + 5], d[maxn + 5], fa[maxn + 5];

inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

int main() {
  scanf("%d %d", &n, &m);
  rep(i, 1, m) {
    scanf("%d %d", &u[i], &v[i]);
    d[u[i]]++, d[v[i]]++;
  }
  rep(i, 1, n) if (d[i] & 1) puts("No"), exit(0);
  rep(i, 1, n) if (d[i] >= 6) puts("Yes"), exit(0);
  int c = 0;
  rep(i, 1, n) c += d[i] == 4;
  if (c != 2)
    puts(c >= 3 ? "Yes" : "No"), exit(0);
  int x = 0;
  rep(i, 1, n) if (d[i] == 4) {
    x = i;
    break;
  }
  rep(i, 1, n) fa[i] = i;
  rep(i, 1, m) if (u[i] != x && v[i] != x) fa[find(u[i])] = v[i];
  int y = 0;
  rep(i, 1, n) y += find(i) == i;
  puts(y == 3 ? "Yes" : "No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template <class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1e5, mod = 1e9 + 7;
int n, m, u[maxn + 5], v[maxn + 5], d[maxn + 5], fa[maxn + 5];

inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

int main() {
  scanf("%d %d", &n, &m);
  rep(i, 1, m) {
    scanf("%d %d", &u[i], &v[i]);
    d[u[i]]++, d[v[i]]++;
  }
  rep(i, 1, n) if (d[i] & 1) puts("No"), exit(0);
  rep(i, 1, n) if (d[i] >= 6) puts("Yes"), exit(0);
  int c = 0;
  rep(i, 1, n) c += d[i] == 4;
  if (c != 2)
    puts(c >= 3 ? "Yes" : "No"), exit(0);
  int x = 0;
  rep(i, 1, n) if (d[i] == 4) {
    x = i;
    break;
  }
  rep(i, 1, n) fa[i] = i;
  rep(i, 1, m) if (u[i] != x && v[i] != x) fa[find(u[i])] = find(v[i]);
  int y = 0;
  rep(i, 1, n) y += find(i) == i;
  puts(y == 3 ? "Yes" : "No");
  return 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

const int MAXN = 100010;
void bye() {
  std::cout << "No\n";
  exit(0);
}
int deg[MAXN], xs[MAXN], ys[MAXN];
int n, m, vis[MAXN], tc;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1];
void addedge(int b, int e, int tot) {
  nxt[++tot] = head[b];
  to[head[b] = tot] = e;
  nxt[++tot] = head[e];
  to[head[e] = tot] = b;
}
int rt;
int dfs(int u, int fa = 0) {
  if (!fa)
    rt = u;
  vis[u] = true;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) {
      if (vis[to[i]] && to[i] == rt) {
        xs[i >> 1] = 0;
        ++tc;
        return true;
      }
      if (dfs(to[i], u)) {
        xs[i >> 1] = 0;
        ++tc;
        return true;
      }
    }
  return false;
}
void reducecir() {
  memset(vis, 0, n + 1 << 2);
  memset(head, 0, n + 1 << 2);
  for (int i = 1; i <= m; ++i)
    if (xs[i])
      addedge(xs[i], ys[i], i * 2 - 1);
  for (int i = 1; i <= n; ++i)
    if (!vis[i] && dfs(i))
      return;
}

int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    std::cin >> xs[i] >> ys[i];
    ++deg[xs[i]];
    ++deg[ys[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (deg[i] & 1)
      bye();
  int cnt = 0, cnt2 = false;
  for (int i = 1; i <= n; ++i)
    cnt += deg[i] == 4, cnt2 |= deg[i] > 4;
  if (!cnt2 && cnt < 3) {
    reducecir();
    if (tc < m)
      reducecir();
    if (tc == m)
      bye();
  }
  std::cout << "Yes\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

const int MAXN = 100010;
void bye() {
  std::cout << "No\n";
  exit(0);
}
int deg[MAXN], xs[MAXN], ys[MAXN];
int n, m, vis[MAXN], tc;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1];
void addedge(int b, int e, int tot) {
  nxt[++tot] = head[b];
  to[head[b] = tot] = e;
  nxt[++tot] = head[e];
  to[head[e] = tot] = b;
}
int rt;
int dfs(int u, int fa = 0) {
  if (!fa)
    rt = u;
  vis[u] = true;
  for (int i = head[u]; i; i = nxt[i])
    if (to[i] != fa) {
      if (vis[to[i]] && to[i] == rt) {
        xs[i >> 1] = 0;
        ++tc;
        return true;
      }
      if (!vis[to[i]] && dfs(to[i], u)) {
        xs[i >> 1] = 0;
        ++tc;
        return true;
      }
    }
  return false;
}
void reducecir() {
  memset(vis, 0, n + 1 << 2);
  memset(head, 0, n + 1 << 2);
  for (int i = 1; i <= m; ++i)
    if (xs[i])
      addedge(xs[i], ys[i], i * 2 - 1);
  for (int i = 1; i <= n; ++i)
    if (!vis[i] && dfs(i))
      return;
}

int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    std::cin >> xs[i] >> ys[i];
    ++deg[xs[i]];
    ++deg[ys[i]];
  }
  for (int i = 1; i <= n; ++i)
    if (deg[i] & 1)
      bye();
  int cnt = 0, cnt2 = false;
  for (int i = 1; i <= n; ++i)
    cnt += deg[i] == 4, cnt2 |= deg[i] > 4;
  if (!cnt2 && cnt < 3) {
    reducecir();
    if (tc < m)
      reducecir();
    if (tc == m)
      bye();
  }
  std::cout << "Yes\n";
  return 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct edge {
  int v, nxt;
} e[500005];
int n, m, h[100005], t, deg[100005], vis[100005];
void add(int u, int v) {
  e[++t].v = v;
  e[t].nxt = h[u];
  h[u] = t;
}
void dfs(int u) {
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v])
      continue;
    dfs(v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
    deg[u]++, deg[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] % 2) {
      printf("No\n");
      return 0;
    }
  int ct = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] >= 6) {
      printf("Yes\n");
      return 0;
    } else if (deg[i] == 4)
      ct++;
  if (ct != 2) {
    if (ct <= 1)
      printf("No\n");
    else
      printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 4) {
      vis[i] = 1;
      break;
    }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2) {
      dfs(i);
      for (int i = 1; i <= n; i++)
        if (!vis[i]) {
          printf("Yes\n");
          return 0;
        }
      printf("No\n");
      return 0;
    }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct edge {
  int v, nxt;
} e[500005];
int n, m, h[100005], t, deg[100005], vis[100005];
void add(int u, int v) {
  e[++t].v = v;
  e[t].nxt = h[u];
  h[u] = t;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (vis[v])
      continue;
    dfs(v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
    deg[u]++, deg[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] % 2) {
      printf("No\n");
      return 0;
    }
  int ct = 0;
  for (int i = 1; i <= n; i++)
    if (deg[i] >= 6) {
      printf("Yes\n");
      return 0;
    } else if (deg[i] == 4)
      ct++;
  if (ct != 2) {
    if (ct <= 1)
      printf("No\n");
    else
      printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 4) {
      vis[i] = 1;
      break;
    }
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2) {
      dfs(i);
      for (int i = 1; i <= n; i++)
        if (!vis[i]) {
          printf("Yes\n");
          return 0;
        }
      printf("No\n");
      return 0;
    }
  return 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define NO return puts("No"), 0
#define YES return puts("Yes"), 0

const int N = 1e5 + 5;
int n, m, cnt, tmp[2], vis[N];
vector<int> G[N];

template <typename _Tp> inline void IN(_Tp &x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-')
      flag = 1;
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  if (flag)
    x = -x;
}

inline void addedge(int u = 0, int v = 0) {
  IN(u), IN(v), G[u].push_back(v), G[v].push_back(u);
}
void dfs(int u) {
  vis[u] = true;
  for (auto v : G[u])
    if (vis[v] == 2)
      tmp[cnt++] = v;
    else
      dfs(v);
}

int main() {
  IN(n), IN(m);
  for (int i = 1; i <= m; ++i)
    addedge();
  int max_du = 0, max_tot = 0;
  for (int i = 1; i <= n; ++i)
    if (G[i].size() & 1)
      NO;
    else if (G[i].size() == max_du)
      ++max_tot;
    else if (G[i].size() > max_du)
      max_du = G[i].size(), max_tot = 1;
  if (max_du >= 6 || (max_du == 4 && max_tot >= 3))
    YES;
  else if (max_du == 2 || max_tot == 1)
    NO;
  else if (max_du == 4 && max_tot == 2) {
    for (int i = 1; i <= n; ++i)
      if (G[i].size() == 4)
        vis[i] = 2;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        cnt = 0, dfs(i);
        if (tmp[0] == tmp[1])
          YES;
      }
  }
  NO;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define NO return puts("No"), 0
#define YES return puts("Yes"), 0

const int N = 1e5 + 5;
int n, m, cnt, tmp[2], vis[N];
vector<int> G[N];

template <typename _Tp> inline void IN(_Tp &x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-')
      flag = 1;
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  if (flag)
    x = -x;
}

inline void addedge(int u = 0, int v = 0) {
  IN(u), IN(v), G[u].push_back(v), G[v].push_back(u);
}
void dfs(int u) {
  vis[u] = true;
  for (auto v : G[u])
    if (vis[v] == 2)
      tmp[cnt++] = v;
    else if (!vis[v])
      dfs(v);
}

int main() {
  IN(n), IN(m);
  for (int i = 1; i <= m; ++i)
    addedge();
  int max_du = 0, max_tot = 0;
  for (int i = 1; i <= n; ++i)
    if (G[i].size() & 1)
      NO;
    else if (G[i].size() == max_du)
      ++max_tot;
    else if (G[i].size() > max_du)
      max_du = G[i].size(), max_tot = 1;
  if (max_du >= 6 || (max_du == 4 && max_tot >= 3))
    YES;
  else if (max_du == 2 || max_tot == 1)
    NO;
  else if (max_du == 4 && max_tot == 2) {
    for (int i = 1; i <= n; ++i)
      if (G[i].size() == 4)
        vis[i] = 2;
    for (int i = 1; i <= n; ++i)
      if (!vis[i]) {
        cnt = 0, dfs(i);
        if (tmp[0] == tmp[1])
          YES;
      }
  }
  NO;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 100000
#define add(x, y) (e[++ee].nxt = lnk[x], ++d[e[lnk[x] = ee].to = y])
using namespace std;
int n, m, ee, d[N + 5], lnk[N + 5];
struct edge {
  int to, nxt;
} e[2 * N + 5];
int tot;
I void DFS(CI s, CI x, CI y, CI lst = 0) {
  if (lst && s == x)
    return;
  if (s == y)
    return (void)(++tot);
  for (RI i = lnk[s]; i; i = e[i].nxt)
    e[i].to ^ lst && (DFS(e[i].to, x, y, s), 0);
}
int main() {
  RI i, x, y, f = 0, t = 0;
  for (scanf("%d%d", &n, &m), i = 1; i <= m; ++i)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  for (i = 1; i <= n; ++i)
    if (d[i] & 1)
      return puts("No"), 0;
    else
      d[i] >= 6 ? f = 1 : d[i] == 4 && (++t, (x ? y : x) = i);
  if (f || t >= 3)
    return puts("Yes"), 0;
  if (t ^ 2)
    return puts("No"), 0;
  return DFS(x, x, y), puts(tot == 2 ? "Yes" : "No"), 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define Tp template <typename Ty>
#define Ts template <typename Ty, typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int &
#define I inline
#define W while
#define N 100000
#define add(x, y) (e[++ee].nxt = lnk[x], ++d[e[lnk[x] = ee].to = y])
using namespace std;
int n, m, ee, d[N + 5], lnk[N + 5];
struct edge {
  int to, nxt;
} e[2 * N + 5];
int tot;
I void DFS(CI s, CI x, CI y, CI lst = 0) {
  if (lst && s == x)
    return;
  if (s == y)
    return (void)(++tot);
  for (RI i = lnk[s]; i; i = e[i].nxt)
    e[i].to ^ lst && (DFS(e[i].to, x, y, s), 0);
}
int main() {
  RI i, x, y, f = 0, t = 0;
  for (scanf("%d%d", &n, &m), i = 1; i <= m; ++i)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  for (x = y = 0, i = 1; i <= n; ++i)
    if (d[i] & 1)
      return puts("No"), 0;
    else
      d[i] >= 6 ? f = 1 : d[i] == 4 && (++t, (x ? y : x) = i);
  if (f || t >= 3)
    return puts("Yes"), 0;
  if (t ^ 2)
    return puts("No"), 0;
  return DFS(x, x, y), puts(tot == 2 ? "Yes" : "No"), 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
int s, t;
void dfs(int crr, int prt) {
  if (crr != prt && crr == s) {
    cout << "Yes" << '\n';
    exit(0);
  }
  for (int nxt : grh[crr]) {
    if (nxt != prt && nxt != t) {
      dfs(nxt, crr);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dgr(n, 0);
  grh.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dgr[--a]++;
    dgr[--b]++;
    grh[a].push_back(b);
    grh[b].push_back(a);
  }
  vector<int> pts;
  for (int i = 0; i < n; i++) {
    if (dgr[i] & 1) {
      cout << "No" << '\n';
      return 0;
    } else if (dgr[i] >= 6) {
      assert(false);
      cout << "Yes" << '\n';
      return 0;
    } else if (dgr[i] == 4) {
      pts.push_back(i);
    }
  }
  if (pts.size() >= 3) {
    cout << "Yes" << '\n';
    return 0;
  } else if (pts.size() <= 1) {
    cout << "No" << '\n';
    return 0;
  }
  s = pts[0];
  t = pts[1];
  dfs(s, s);
  cout << "No" << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
int s, t;
void dfs(int crr, int prt) {
  if (crr != prt && crr == s) {
    cout << "Yes" << '\n';
    exit(0);
  }
  for (int nxt : grh[crr]) {
    if (nxt != prt && nxt != t) {
      dfs(nxt, crr);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dgr(n, 0);
  grh.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    dgr[--a]++;
    dgr[--b]++;
    grh[a].push_back(b);
    grh[b].push_back(a);
  }
  vector<int> pts;
  for (int i = 0; i < n; i++) {
    if (dgr[i] & 1) {
      cout << "No" << '\n';
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (dgr[i] >= 6) {
      cout << "Yes" << '\n';
      return 0;
    } else if (dgr[i] == 4) {
      pts.push_back(i);
    }
  }
  if (pts.size() >= 3) {
    cout << "Yes" << '\n';
    return 0;
  } else if (pts.size() <= 1) {
    cout << "No" << '\n';
    return 0;
  }
  s = pts[0];
  t = pts[1];
  dfs(s, s);
  cout << "No" << '\n';
  return 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
// 18:10~
#include <bits/stdc++.h>
using namespace std;

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

  int n, m;
  static int deg[100000];
  static vector<int> edges[100000];

  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ++deg[a];
    ++deg[b];
  }
  static bool odd, six;
  vector<int> four;
  for (int i = 0; i < n; ++i) {
    if (deg[i] & 1)
      odd = true;
    if (deg[i] >= 6)
      six = true;
    if (deg[i] == 4)
      four.emplace_back(i);
  }
  if (odd)
    cout << "No" << endl;
  else if (six)
    cout << "Yes" << endl;
  else if (four.size() >= 3)
    cout << "Yes" << endl;
  else if (four.size() <= 1)
    cout << "No" << endl;
  else {
    for (int i = 0; i < 4; ++i) {
      queue<pair<int, int>> q;
      q.emplace(edges[four[0]][i], four[0]);
      while (!q.empty()) {
        auto t = q.front();
        q.pop();
        if (t.first == four[1])
          break;
        if (t.first == four[0]) {
          cout << "Yes" << endl;
          return 0;
        }
        for (int to : edges[t.first]) {
          if (to == t.second)
            continue;
          q.emplace(to, t.first);
        }
      }
    }
    cout << "No" << endl;
  }

  return 0;
}

Fixed submission:
// 18:10~
#include <bits/stdc++.h>
using namespace std;

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

  int n, m;
  static int deg[100000];
  static vector<int> edges[100000];

  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    ++deg[a];
    ++deg[b];
    edges[a].emplace_back(b);
    edges[b].emplace_back(a);
  }
  static bool odd, six;
  vector<int> four;
  for (int i = 0; i < n; ++i) {
    if (deg[i] & 1)
      odd = true;
    if (deg[i] >= 6)
      six = true;
    if (deg[i] == 4)
      four.emplace_back(i);
  }
  if (odd)
    cout << "No" << endl;
  else if (six)
    cout << "Yes" << endl;
  else if (four.size() >= 3)
    cout << "Yes" << endl;
  else if (four.size() <= 1)
    cout << "No" << endl;
  else {
    for (int i = 0; i < 4; ++i) {
      queue<pair<int, int>> q;
      q.emplace(edges[four[0]][i], four[0]);
      while (!q.empty()) {
        auto t = q.front();
        q.pop();
        if (t.first == four[1])
          break;
        if (t.first == four[0]) {
          cout << "Yes" << endl;
          return 0;
        }
        for (int to : edges[t.first]) {
          if (to == t.second)
            continue;
          q.emplace(to, t.first);
        }
      }
    }
    cout << "No" << endl;
  }

  return 0;
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
using namespace std;
#define N 100500
struct edge {
  int t, next;
} ed[N];
int head[N], cnt = 1, in[N], n, m, ct, mx, fg, a, b, vis[N];
void adde(int f, int t) {
  ed[++cnt] = (edge){t, head[f]};
  head[f] = cnt;
  ed[++cnt] = (edge){f, head[t]};
  head[t] = cnt;
  in[f]++;
  in[t]++;
}
void dfs(int u, int id) {
  vis[u] = 1;
  if (u == b)
    fg = 1, vis[u] = 0;
  if (u == a && id)
    return;
  for (int i = head[u]; i; i = ed[i].next)
    if (i != id && i != (id ^ 1) && !vis[ed[i].t])
      dfs(ed[i].t, i);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &a, &b), adde(a, b);
  a = -1;
  for (int i = 1; i <= n; i++)
    if (in[i] & 1) {
      printf("No\n");
      return 0;
    } else if (mx < in[i])
      mx = in[i];
  if (mx > 4) {
    printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (in[i] == 4) {
      ct++;
      if (a == -1)
        a = i;
      else
        b = i;
    }
  if (ct > 2) {
    printf("Yes\n");
    return 0;
  }
  if (ct == 2)
    for (int i = head[a]; i; i = ed[i].next)
      if (!vis[ed[i].t]) {
        fg = 0;
        dfs(ed[i].t, 1);
        if (!fg) {
          printf("Yes\n");
          return 0;
        }
      }
  printf("No\n");
}

Fixed submission:
#include <cstdio>
using namespace std;
#define N 100500
struct edge {
  int t, next;
} ed[N * 2];
int head[N], cnt = 1, in[N], n, m, ct, mx, fg, a, b, vis[N];
void adde(int f, int t) {
  ed[++cnt] = (edge){t, head[f]};
  head[f] = cnt;
  ed[++cnt] = (edge){f, head[t]};
  head[t] = cnt;
  in[f]++;
  in[t]++;
}
void dfs(int u, int id) {
  vis[u] = 1;
  if (u == b)
    fg = 1, vis[u] = 0;
  if (u == a && id)
    return;
  for (int i = head[u]; i; i = ed[i].next)
    if (i != id && i != (id ^ 1) && !vis[ed[i].t])
      dfs(ed[i].t, i);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &a, &b), adde(a, b);
  a = -1;
  for (int i = 1; i <= n; i++)
    if (in[i] & 1) {
      printf("No\n");
      return 0;
    } else if (mx < in[i])
      mx = in[i];
  if (mx > 4) {
    printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (in[i] == 4) {
      ct++;
      if (a == -1)
        a = i;
      else
        b = i;
    }
  if (ct > 2) {
    printf("Yes\n");
    return 0;
  }
  if (ct == 2)
    for (int i = head[a]; i; i = ed[i].next)
      if (!vis[ed[i].t]) {
        fg = 0;
        dfs(ed[i].t, 1);
        if (!fg) {
          printf("Yes\n");
          return 0;
        }
      }
  printf("No\n");
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, i, d[1000005], u, v, ans, head[1000005], Next[2000005], adj[2000005],
    k, s;
bool flag = true;
void Push(int u, int v) {
  Next[++k] = head[u];
  head[u] = k;
  adj[k] = v;
}
void dfs(int i, int fa) {
  if ((i == u && fa != 0) || i == v) {
    if (i == v)
      ++s;
    return;
  }
  int j;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa)
      dfs(adj[j], i);
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d %d", &u, &v);
    ++d[u];
    ++d[v];
    Push(u, v);
    Push(v, u);
  }
  for (i = 1; i <= n; ++i) {
    ans += d[i] / 2 - 1;
    if (d[i] & 1)
      flag = false;
  }
  for (i = 1; i <= n; ++i)
    if (d[i] == 4)
      if (u == 0)
        u = i;
      else
        v = i;
  if (ans == 2 && v != 0 && flag) {
    dfs(u, 0);
    if (s > 2)
      flag = false;
  }
  puts(ans >= 2 && flag ? "Yes" : "No");
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, i, d[1000005], u, v, ans, head[1000005], Next[2000005], adj[2000005],
    k, s;
bool flag = true;
void Push(int u, int v) {
  Next[++k] = head[u];
  head[u] = k;
  adj[k] = v;
}
void dfs(int i, int fa) {
  if ((i == u && fa != 0) || i == v) {
    if (i == v)
      ++s;
    return;
  }
  int j;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa)
      dfs(adj[j], i);
}
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d %d", &u, &v);
    ++d[u];
    ++d[v];
    Push(u, v);
    Push(v, u);
  }
  for (i = 1; i <= n; ++i) {
    ans += d[i] / 2 - 1;
    if (d[i] & 1)
      flag = false;
  }
  u = v = 0;
  for (i = 1; i <= n; ++i)
    if (d[i] == 4)
      if (u == 0)
        u = i;
      else
        v = i;
  if (ans == 2 && v != 0 && flag) {
    dfs(u, 0);
    if (s > 2)
      flag = false;
  }
  puts(ans >= 2 && flag ? "Yes" : "No");
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N = 1e5 + 100;
int n, m, dg[N], vi[N], fb;
int tot, first[N], nxt[N * 2], point[N * 2];
bool ok;
vector<int> f;
inline void add_edge(int x, int y) {
  tot++;
  nxt[tot] = first[x];
  first[x] = tot;
  point[tot] = y;
}
void dfs(int x, int fa) {
  if (f[0] == x && fa != 0)
    ok = 1;
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (u == fa || u == f[1])
      continue;
    dfs(u, x);
  }
}
signed main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  memset(nxt, -1, sizeof(nxt));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
    dg[u]++;
    dg[v]++;
  }
  bool bl = 1;
  for (int i = 1; i <= n; i++) {
    if (dg[i] & 1) {
      bl = 0;
      break;
    }
  }
  if (!bl) {
    printf("No\n");
    return 0;
  }
  int MAX = 0, cnt = 0;
  for (int i = 1; i <= n; i++)
    MAX = max(MAX, dg[i]);
  for (int i = 1; i <= n; i++)
    if (dg[i] == MAX)
      cnt++;
  if (MAX < 4 || (MAX == 4 && cnt < 2)) {
    printf("No\n");
    return 0;
  }
  if (MAX > 4 || (MAX == 4 && cnt > 2)) {
    printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (dg[i] == MAX)
      f.push_back(i);
  ok = 0;
  dfs(f[0], 0);
  if (ok)
    printf("Yes\n");
  else
    printf("No\n");
}

Fixed submission:
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N = 1e5 + 100;
int n, m, dg[N], vi[N], fb;
int tot, first[N], nxt[N * 2], point[N * 2];
bool ok;
vector<int> f;
inline void add_edge(int x, int y) {
  tot++;
  nxt[tot] = first[x];
  first[x] = tot;
  point[tot] = y;
}
void dfs(int x, int fa) {
  if (f[0] == x && fa != 0)
    ok = 1;
  if (ok)
    return;
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (u == fa || u == f[1])
      continue;
    dfs(u, x);
  }
}
signed main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  memset(nxt, -1, sizeof(nxt));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
    dg[u]++;
    dg[v]++;
  }
  bool bl = 1;
  for (int i = 1; i <= n; i++) {
    if (dg[i] & 1) {
      bl = 0;
      break;
    }
  }
  if (!bl) {
    printf("No\n");
    return 0;
  }
  int MAX = 0, cnt = 0;
  for (int i = 1; i <= n; i++)
    MAX = max(MAX, dg[i]);
  for (int i = 1; i <= n; i++)
    if (dg[i] == MAX)
      cnt++;
  if (MAX < 4 || (MAX == 4 && cnt < 2)) {
    printf("No\n");
    return 0;
  }
  if (MAX > 4 || (MAX == 4 && cnt > 2)) {
    printf("Yes\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (dg[i] == MAX)
      f.push_back(i);
  ok = 0;
  dfs(f[0], 0);
  if (ok)
    printf("Yes\n");
  else
    printf("No\n");
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PB push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define CLR(a, v) memset(a, v, sizeof(a));
#define CPY(a, b) memcpy(a, b, sizeof(a));
using namespace std;
const int N = 100005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], tot, n, m, cnt;
int deg[N], vis[N], q4[N];
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void findpath(int x, int fa) {
  if (x == q4[2])
    return ++cnt, void(0);
  if (x == q4[1] && fa)
    return;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa)
      findpath(e[i].to, x);
}
int main() {
  scanf("%d%d", &n, &m);
  For(i, 1, m) {
    int x, y;
    scanf("%d%d", &x, &y);
    ++deg[x];
    ++deg[y];
    add(x, y);
    add(y, x);
  }
  int S6 = 0, S4 = 0;
  For(i, 1, n) if (deg[i] & 1) return puts("No"), 0;
  else if (deg[i] >= 6)++ S6;
  else if (deg[i] == 4) q4[++S4] = i;
  if (S6 || S4 > 3)
    return puts("Yes"), 0;
  if (S4 < 1)
    return puts("No"), 0;
  vis[q4[1]] = vis[q4[2]] = 1;
  findpath(q4[1], 0);
  puts(cnt == 2 ? "Yes" : "No");
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int, int>
#define pll pair<ll, ll>
#define PB push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = (int)(j); i <= (int)(k); i++)
#define Rep(i, j, k) for (int i = (int)(j); i >= (int)(k); i--)
#define CLR(a, v) memset(a, v, sizeof(a));
#define CPY(a, b) memcpy(a, b, sizeof(a));
using namespace std;
const int N = 100005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], tot, n, m, cnt;
int deg[N], vis[N], q4[N];
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void findpath(int x, int fa) {
  if (x == q4[2])
    return ++cnt, void(0);
  if (x == q4[1] && fa)
    return;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa)
      findpath(e[i].to, x);
}
int main() {
  scanf("%d%d", &n, &m);
  For(i, 1, m) {
    int x, y;
    scanf("%d%d", &x, &y);
    ++deg[x];
    ++deg[y];
    add(x, y);
    add(y, x);
  }
  int S6 = 0, S4 = 0;
  For(i, 1, n) if (deg[i] & 1) return puts("No"), 0;
  else if (deg[i] >= 6)++ S6;
  else if (deg[i] == 4) q4[++S4] = i;
  if (S6 || S4 >= 3)
    return puts("Yes"), 0;
  if (S4 < 1)
    return puts("No"), 0;
  vis[q4[1]] = vis[q4[2]] = 1;
  findpath(q4[1], 0);
  puts(cnt == 2 ? "Yes" : "No");
}
Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

vector<int> edge[100005];
int dfn[100005], dfnn, X, Y;

int dfs(int x, int p, int c) {
  int ret = 0;
  dfn[x] = ++dfnn;
  if (x == Y)
    c = 1;
  for (auto i : edge[x]) {
    if (i == p)
      continue;
    if (dfn[i]) {
      if (i == X && c)
        ret++;
      continue;
    }
    ret += dfs(i, x, c);
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  int flag = 0;
  vector<int> vec;
  for (int i = 1; i <= N; ++i) {
    if (edge[i].size() & 1)
      return !puts("No");
    if (edge[i].size() >= 6)
      flag = 1;
    if (edge[i].size() == 4)
      vec.push_back(i);
  }
  if (flag || vec.size() > 2)
    puts("Yes");
  else {
    X = vec[0];
    Y = vec[1];
    if (vec.size() == 2 && dfs(vec[0], 0, 0) == 1)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}

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

vector<int> edge[100005];
int dfn[100005], dfnn, X, Y;

int dfs(int x, int p, int c) {
  int ret = 0;
  dfn[x] = ++dfnn;
  if (x == Y)
    c = 1;
  for (auto i : edge[x]) {
    if (i == p)
      continue;
    if (dfn[i]) {
      if (i == X && c)
        ret++;
      continue;
    }
    ret += dfs(i, x, c);
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int x, y;
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  int flag = 0;
  vector<int> vec;
  for (int i = 1; i <= N; ++i) {
    if (edge[i].size() & 1)
      return !puts("No");
    if (edge[i].size() >= 6)
      flag = 1;
    if (edge[i].size() == 4)
      vec.push_back(i);
  }
  if (flag || vec.size() > 2)
    puts("Yes");
  else {
    if (vec.size() == 2) {
      X = vec[0];
      Y = vec[1];
    }
    if (vec.size() == 2 && dfs(vec[0], 0, 0) == 1)
      puts("Yes");
    else
      puts("No");
  }
  return 0;
}