Problem p03746 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define trace(x) cout << #x << " = " << x << '\n'
#define trace2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << '\n'
#define trace3(x, y, z)                                                        \
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \
       << z << '\n'
#define sz(x) (int)(x).size()
using namespace std;
struct ii {
  int a, b;
  bool operator<(ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
  int a, b, c;
  bool operator<(iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, N, M, K, Q, x, y, z;

vector<int> edge[MAXN];
bool sudah[MAXN];
deque<int> deq;

int main() {
#ifdef FAIRUZI10
  freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
#endif

  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  deq.push_back(1);
  deq.push_back(edge[1][0]);
  sudah[1] = sudah[edge[1][0]] = 1;
  while (1) {
    bool suc = 1;
    for (auto i : edge[deq.front()]) {
      if (!sudah[i]) {
        suc = 0;
        deq.push_front(i);
        sudah[i] = 1;
        break;
      }
    }
    for (auto i : edge[deq.back()]) {
      if (!sudah[i]) {
        suc = 0;
        deq.push_back(i);
        sudah[i] = 1;
        break;
      }
    }
    if (suc) {
      printf("%d\n", sz(deq));
      printf("%d", deq.front());
      for (int i = 1; i < sz(deq); i++)
        printf(" %d", deq[i]);
      puts("");
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define trace(x) cout << #x << " = " << x << '\n'
#define trace2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << '\n'
#define trace3(x, y, z)                                                        \
  cout << #x << " = " << x << " " << #y << " = " << y << " " << #z << " = "    \
       << z << '\n'
#define sz(x) (int)(x).size()
using namespace std;
struct ii {
  int a, b;
  bool operator<(ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
  int a, b, c;
  bool operator<(iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, N, M, K, Q, x, y, z;

vector<int> edge[MAXN];
bool sudah[MAXN];
deque<int> deq;

int main() {
#ifdef FAIRUZI10
  freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
#endif

  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d", &x, &y);
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  deq.push_back(1);
  deq.push_back(edge[1][0]);
  sudah[1] = sudah[edge[1][0]] = 1;
  while (1) {
    bool suc = 1;
    for (auto i : edge[deq.front()]) {
      if (!sudah[i]) {
        suc = 0;
        deq.push_front(i);
        sudah[i] = 1;
        break;
      }
    }
    for (auto i : edge[deq.back()]) {
      if (!sudah[i]) {
        suc = 0;
        deq.push_back(i);
        sudah[i] = 1;
        break;
      }
    }
    if (suc) {
      printf("%d\n", sz(deq));
      printf("%d", deq.front());
      for (int i = 1; i < sz(deq); i++)
        printf(" %d", deq[i]);
      puts("");
      return 0;
    }
  }

  return 0;
}