Problem p03091 (C++)

Buggy submission (status: Runtime Error):
/*
Rathin Bhargava
IIIT Bangalore

*/
#include <bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pr(v)                                                                  \
  {                                                                            \
    for (int i = 0; i < v.size(); i++) {                                       \
      v[i] == INF ? cout << "INF " : cout << v[i] << " ";                      \
    }                                                                          \
    cout << endl;                                                              \
  }
#define t1(x) cerr << #x << " : " << x << endl
#define t2(x, y) cerr << #x << " : " << x << " " << #y << " : " << y << endl
#define t3(x, y, z)                                                            \
  cerr << #x << " : " << x << " " << #y << " : " << y << " " << #z << " : "    \
       << z << endl
#define t4(a, b, c, d)                                                         \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << endl
#define t5(a, b, c, d, e)                                                      \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << " " << #e << " : " << e << endl
#define t6(a, b, c, d, e, f)                                                   \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << " " << #e << " : " << e << " " << #f \
       << " : " << f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr << "here" << endl;
#define __                                                                     \
  {                                                                            \
    ios::sync_with_stdio(false);                                               \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }

using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <int> ostream &operator<<(ostream &os, const vector<int> &v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] != INF)
      os << v[i];
    else
      os << "INF";
    if (i != v.size() - 1)
      os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    ;
    if (i != v.size() - 1)
      os << ", ";
  }
  os << "]\n";
  return os;
}

const int N = 1e5 + 100;
vector<int> adj[N] = {};
vector<int> vis(N);
map<pair<int, int>, int> edges;

int dfs(int u, int root, int root2, int parent) {
  while (u != root && u != root2) {
    u = adj[u][0] + adj[u][1] - parent;
    parent = u;
  }
  if (u == root2)
    return 1;
  return 0;
}

int main() {
  __;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;

    adj[a].pu(b);
    adj[b].pu(a);
    edges[{a, b}] = edges[{b, a}] = 0;
  }

  bool boo = false;
  int idx = -1;
  int cnt = 0;
  vector<int> id;
  for (int i = 0; i < n; i++)
    if (adj[i].size() % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }

  for (int i = 0; i < n; i++) {
    if (adj[i].size() >= 6) {
      cout << "Yes" << endl;
      return 0;
    } else if (adj[i].size() == 4) {
      cnt++;
      id.pu(i);
      boo = true;
    }
  }

  if (cnt > 2) {
    cout << "Yes" << endl;
    return 0;
  } else if (cnt <= 1) {
    cout << "No" << endl;
    return 0;
  }

  int root = id[0], root2 = id[1];

  int paths = 0;
  for (auto v : adj[root]) {
    paths += dfs(v, root, root2, root);
  }

  if (paths == 4)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Fixed submission:
/*
Rathin Bhargava
IIIT Bangalore

*/
#include <bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pr(v)                                                                  \
  {                                                                            \
    for (int i = 0; i < v.size(); i++) {                                       \
      v[i] == INF ? cout << "INF " : cout << v[i] << " ";                      \
    }                                                                          \
    cout << endl;                                                              \
  }
#define t1(x) cerr << #x << " : " << x << endl
#define t2(x, y) cerr << #x << " : " << x << " " << #y << " : " << y << endl
#define t3(x, y, z)                                                            \
  cerr << #x << " : " << x << " " << #y << " : " << y << " " << #z << " : "    \
       << z << endl
#define t4(a, b, c, d)                                                         \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << endl
#define t5(a, b, c, d, e)                                                      \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << " " << #e << " : " << e << endl
#define t6(a, b, c, d, e, f)                                                   \
  cerr << #a << " : " << a << " " << #b << " : " << b << " " << #c << " : "    \
       << c << " " << #d << " : " << d << " " << #e << " : " << e << " " << #f \
       << " : " << f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr << "here" << endl;
#define __                                                                     \
  {                                                                            \
    ios::sync_with_stdio(false);                                               \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }

using namespace std;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <int> ostream &operator<<(ostream &os, const vector<int> &v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] != INF)
      os << v[i];
    else
      os << "INF";
    if (i != v.size() - 1)
      os << ", ";
  }
  os << "]\n";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  for (int i = 0; i < v.size(); ++i) {
    os << v[i];
    ;
    if (i != v.size() - 1)
      os << ", ";
  }
  os << "]\n";
  return os;
}

const int N = 1e5 + 100;
vector<int> adj[N] = {};
vector<int> vis(N);
map<pair<int, int>, int> edges;

int dfs(int u, int root, int root2, int parent) {
  while (u != root && u != root2) {
    parent = adj[u][0] + adj[u][1] - parent;
    swap(parent, u);
  }
  if (u == root2)
    return 1;
  return 0;
}

int main() {
  __;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;

    adj[a].pu(b);
    adj[b].pu(a);
    edges[{a, b}] = edges[{b, a}] = 0;
  }

  bool boo = false;
  int idx = -1;
  int cnt = 0;
  vector<int> id;
  for (int i = 0; i < n; i++)
    if (adj[i].size() % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }

  for (int i = 0; i < n; i++) {
    if (adj[i].size() >= 6) {
      cout << "Yes" << endl;
      return 0;
    } else if (adj[i].size() == 4) {
      cnt++;
      id.pu(i);
      boo = true;
    }
  }

  if (cnt > 2) {
    cout << "Yes" << endl;
    return 0;
  } else if (cnt <= 1) {
    cout << "No" << endl;
    return 0;
  }

  int root = id[0], root2 = id[1];

  int paths = 0;
  for (auto v : adj[root]) {
    paths += dfs(v, root, root2, root);
  }

  if (paths == 4)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}