Problem p03662 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int, int>>
#define F first
#define S second
#define RF(x) freopen(x, "r", stdin)
#define WF(x) freopen(x, "w", stdout)
typedef long long LL;
using namespace std;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PII;
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;
const double eps = 1e-13;

vector<int> adj[10009];
int dist[100009][2];

void dfs(int x, int t, int p = -1) {
  for (int i : adj[x]) {
    if (i == p)
      continue;
    dist[i][t] = dist[x][t] + 1;
    dfs(i, t, x);
  }
}

int main() {
  DRI(n);
  REP(i, n - 1) {
    DRII(a, b);
    a--;
    b--;
    adj[a].PB(b);
    adj[b].PB(a);
  }
  dfs(0, 0);
  dfs(n - 1, 1);
  int f = 0, s = 0;
  REP(x, n) {
    if (dist[x][0] <= dist[x][1])
      f++;
    else
      s++;
  }
  // printf("%d %d",f,s);
  if (f > s)
    puts("Fennec");
  else
    puts("Snuke");
}


Fixed submission:
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X)                                                                 \
  int(X);                                                                      \
  scanf("%d", &X)
#define DRII(X, Y)                                                             \
  int X, Y;                                                                    \
  scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z)                                                         \
  int X, Y, Z;                                                                 \
  scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET                                                                  \
  int ___T, case_n = 1;                                                        \
  scanf("%d ", &___T);                                                         \
  while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define VPII vector<pair<int, int>>
#define F first
#define S second
#define RF(x) freopen(x, "r", stdin)
#define WF(x) freopen(x, "w", stdout)
typedef long long LL;
using namespace std;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PII;
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;
const double eps = 1e-13;

vector<int> adj[100009];
int dist[100009][2];

void dfs(int x, int t, int p = -1) {
  for (int i : adj[x]) {
    if (i == p)
      continue;
    dist[i][t] = dist[x][t] + 1;
    dfs(i, t, x);
  }
}

int main() {
  DRI(n);
  REP(i, n - 1) {
    DRII(a, b);
    a--;
    b--;
    adj[a].PB(b);
    adj[b].PB(a);
  }
  dfs(0, 0);
  dfs(n - 1, 1);
  int f = 0, s = 0;
  REP(x, n) {
    if (dist[x][0] <= dist[x][1])
      f++;
    else
      s++;
  }
  // printf("%d %d",f,s);
  if (f > s)
    puts("Fennec");
  else
    puts("Snuke");
}