Problem p03091 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, a, b) for (int i = a; i >= b; --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> pa;
typedef vector<int> vec;
void getint(int &v) {
  char ch, fu = 0;
  for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-')
    fu = 1, ch = getchar();
  for (v = 0; ch >= '0' && ch <= '9'; ch = getchar())
    v = v * 10 + ch - '0';
  if (fu)
    v = -v;
}
bool v[500010];
int nedge, too[500010], hed[500010], x[500010], y[500010], nxt[500010], n, m,
    d[500010], d4, A, B;
void ae(int x, int y) {
  nxt[++nedge] = hed[x];
  hed[x] = nedge;
  too[nedge] = y;
}
void dfs(int x) {
  v[x] = 1;
  for (int i = hed[x]; i; i = nxt[i]) {
    int y = too[i];
    if (y == B)
      continue;
    dfs(y);
  }
}
int main() {
  cin >> n >> m;
  if (n == 1)
    return puts("No"), 0;
  FOR(i, 1, m) {
    getint(x[i]), getint(y[i]);
    ++d[x[i]], ++d[y[i]];
    ae(x[i], y[i]), ae(y[i], x[i]);
  }
  FOR(i, 1, n) if (d[i] & 1) return puts("No"), 0;
  FOR(i, 1, n) if (d[i] >= 6) return puts("Yes"), 0;
  FOR(i, 1, n) if (d[i] >= 4)++ d4;
  if (d4 >= 3)
    return puts("Yes"), 0;
  if (d4 <= 1)
    return puts("No"), 0;
  FOR(i, 1, n) if (d[i] == 4) A = i;
  FOR(i, 1, n) if (d[i] == 4 && i != A) B = i;
  dfs(A);
  for (int i = hed[B]; i; i = nxt[i]) {
    int y = too[i];
    if (!v[y])
      return puts("Yes"), 0;
  }
  puts("No");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, a, b) for (int i = a; i >= b; --i)
using namespace std;
typedef long long LL;
typedef pair<int, int> pa;
typedef vector<int> vec;
void getint(int &v) {
  char ch, fu = 0;
  for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-')
    fu = 1, ch = getchar();
  for (v = 0; ch >= '0' && ch <= '9'; ch = getchar())
    v = v * 10 + ch - '0';
  if (fu)
    v = -v;
}
bool v[500010];
int nedge, too[500010], hed[500010], x[500010], y[500010], nxt[500010], n, m,
    d[500010], d4, A, B;
void ae(int x, int y) {
  nxt[++nedge] = hed[x];
  hed[x] = nedge;
  too[nedge] = y;
}
void dfs(int x) {
  v[x] = 1;
  for (int i = hed[x]; i; i = nxt[i]) {
    int y = too[i];
    if (y == B || v[y])
      continue;
    dfs(y);
  }
}
int main() {
  cin >> n >> m;
  if (n == 1)
    return puts("No"), 0;
  FOR(i, 1, m) {
    getint(x[i]), getint(y[i]);
    ++d[x[i]], ++d[y[i]];
    ae(x[i], y[i]), ae(y[i], x[i]);
  }
  FOR(i, 1, n) if (d[i] & 1) return puts("No"), 0;
  FOR(i, 1, n) if (d[i] >= 6) return puts("Yes"), 0;
  FOR(i, 1, n) if (d[i] >= 4)++ d4;
  if (d4 >= 3)
    return puts("Yes"), 0;
  if (d4 <= 1)
    return puts("No"), 0;
  FOR(i, 1, n) if (d[i] == 4) A = i;
  FOR(i, 1, n) if (d[i] == 4 && i != A) B = i;
  dfs(A);
  for (int i = hed[B]; i; i = nxt[i]) {
    int y = too[i];
    if (!v[y])
      return puts("Yes"), 0;
  }
  puts("No");
  return 0;
}