Problem p03660 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#pragma region
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 1111

int main(void) {
  vll edge[MAX];
  queue<ll> que;
  ll d1[MAX], dn[MAX];
  ll a, b;
  cin >> n;
  FOR(i, 0, n - 1) {
    cin >> a >> b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  FOR(i, 1, n + 1) {
    d1[i] = INF;
    dn[i] = INF;
  }
  d1[1] = 0;
  dn[n] = 0;

  que.push(1);
  while (!que.empty()) {
    tmp = que.front();
    que.pop();
    FOR(j, 0, edge[tmp].size()) {
      m = edge[tmp][j];
      if (d1[m] == INF) {
        que.push(m);
        d1[m] = d1[tmp] + 1;
      }
    }
  }

  que.push(n);
  while (!que.empty()) {
    tmp = que.front();
    que.pop();
    FOR(j, 0, edge[tmp].size()) {
      m = edge[tmp][j];
      if (dn[m] == INF) {
        que.push(m);
        dn[m] = dn[tmp] + 1;
      }
    }
  }

  FOR(i, 1, n + 1) {
    if (d1[i] <= dn[i])
      cnt++;
  }

  if (cnt > (n - cnt)) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#pragma region
using namespace std;
#define FOR(i, r, n) for (ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i, r, n) for (ll i = (ll)(n - 1); i >= r; i--)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111

int main(void) {
  vll edge[MAX];
  queue<ll> que;
  ll d1[MAX], dn[MAX];
  ll a, b;
  cin >> n;
  FOR(i, 0, n - 1) {
    cin >> a >> b;
    edge[a].pb(b);
    edge[b].pb(a);
  }
  FOR(i, 1, n + 1) {
    d1[i] = INF;
    dn[i] = INF;
  }
  d1[1] = 0;
  dn[n] = 0;

  que.push(1);
  while (!que.empty()) {
    tmp = que.front();
    que.pop();
    FOR(j, 0, edge[tmp].size()) {
      m = edge[tmp][j];
      if (d1[m] == INF) {
        que.push(m);
        d1[m] = d1[tmp] + 1;
      }
    }
  }

  que.push(n);
  while (!que.empty()) {
    tmp = que.front();
    que.pop();
    FOR(j, 0, edge[tmp].size()) {
      m = edge[tmp][j];
      if (dn[m] == INF) {
        que.push(m);
        dn[m] = dn[tmp] + 1;
      }
    }
  }

  FOR(i, 1, n + 1) {
    if (d1[i] <= dn[i])
      cnt++;
  }

  if (cnt > (n - cnt)) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }

  return 0;
}