Problem p03660 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
  ll n;
  vvll t(n, vll(0));
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].pb(b);
    t[b].pb(a);
  }
  vll f(n);
  vll ss(n);
  queue<ll> p;
  vb ch(n, false);
  p.pu(0);
  ch[0] = true;
  while (sz(p)) {
    ll s = p.front();
    p.pop();
    for (auto pp : t[s]) {
      if (ch[pp])
        continue;
      ch[pp] = true;
      f[pp] = f[s] + 1;
      p.pu(pp);
    }
  }
  vb cch(n, false);
  p.pu(n - 1);
  cch[n - 1] = true;
  while (sz(p)) {
    ll s = p.front();
    p.pop();
    for (auto pp : t[s]) {
      if (cch[pp])
        continue;
      cch[pp] = true;
      ss[pp] = ss[s] + 1;
      p.pu(pp);
    }
  }
  ll ff = 0;
  ll sss = 0;
  rep(i, n) {
    if (f[i] <= ss[i]) {
      ff++;
    } else
      sss++;
  }
  if (ff > sss)
    COUT("Fennec");
  else
    COUT("Snuke");
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (b); i++)
#define repR(i, n) for (ll i = n; i >= 0; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, vector<ll>, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define mp make_pair
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
int main() {
  ll n;
  cin >> n;

  vvll t(n, vll(0));
  rep(i, n - 1) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    t[a].pb(b);
    t[b].pb(a);
  }
  vll f(n);
  vll ss(n);
  queue<ll> p;
  vb ch(n, false);
  p.pu(0);
  ch[0] = true;
  while (sz(p)) {
    ll s = p.front();
    p.pop();
    for (auto pp : t[s]) {
      if (ch[pp])
        continue;
      ch[pp] = true;
      f[pp] = f[s] + 1;
      p.pu(pp);
    }
  }
  vb cch(n, false);
  p.pu(n - 1);
  cch[n - 1] = true;
  while (sz(p)) {
    ll s = p.front();
    p.pop();
    for (auto pp : t[s]) {
      if (cch[pp])
        continue;
      cch[pp] = true;
      ss[pp] = ss[s] + 1;
      p.pu(pp);
    }
  }
  ll ff = 0;
  ll sss = 0;
  rep(i, n) {
    if (f[i] <= ss[i]) {
      ff++;
    } else
      sss++;
  }
  if (ff > sss)
    COUT("Fennec");
  else
    COUT("Snuke");
}