Problem p03746 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop                                                                   \
  char nyaa;                                                                   \
  cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll, P> PP;
int main() {
  vector<int> le, ri;
  vector<int> G[100000];
  bool used[100000];
  int n, m;
  cin >> n >> m;
  fill(used, used + n, false);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  le.push_back(0);
  ri.push_back(G[0][0]);
  used[0] = used[G[0][0]] = true;
  int now = 0;
  while (true) {
    int len = G[now].size();
    bool g = true;
    rep(i, len) {
      int v = G[now][i];
      if (!used[v]) {
        le.push_back(v);
        now = v;
        used[v] = true;
        g = false;
        break;
      }
    }
    if (g)
      break;
  }
  now = G[0][0];
  while (true) {
    int len = G[now].size();
    bool g = true;
    rep(i, len) {
      int v = G[now][i];
      if (!used[v]) {
        ri.push_back(v);
        now = v;
        used[v] = true;
        g = false;
      }
    }
    if (g)
      break;
  }
  int l1 = le.size();
  int l2 = ri.size();
  cout << l1 + l2 << endl;
  per(i, l1) {
    if (i < l1 - 1)
      cout << " ";
    cout << le[i] + 1;
  }
  rep(i, l2) { cout << " " << ri[i] + 1; }
  cout << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop                                                                   \
  char nyaa;                                                                   \
  cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<ll, P> PP;
int main() {
  vector<int> le, ri;
  vector<int> G[100000];
  bool used[100000];
  int n, m;
  cin >> n >> m;
  fill(used, used + n, false);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  le.push_back(0);
  ri.push_back(G[0][0]);
  used[0] = used[G[0][0]] = true;
  int now = 0;
  while (true) {
    int len = G[now].size();
    bool g = true;
    rep(i, len) {
      int v = G[now][i];
      if (!used[v]) {
        le.push_back(v);
        now = v;
        used[v] = true;
        g = false;
        break;
      }
    }
    if (g)
      break;
  }
  now = G[0][0];
  while (true) {
    int len = G[now].size();
    bool g = true;
    rep(i, len) {
      int v = G[now][i];
      if (!used[v]) {
        ri.push_back(v);
        now = v;
        used[v] = true;
        g = false;
        break;
      }
    }
    if (g)
      break;
  }
  int l1 = le.size();
  int l2 = ri.size();
  cout << l1 + l2 << endl;
  per(i, l1) {
    if (i < l1 - 1)
      cout << " ";
    cout << le[i] + 1;
  }
  rep(i, l2) { cout << " " << ri[i] + 1; }
  cout << endl;
  return 0;
}