Problem p03662 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x, y)                                                          \
  cerr << #x << " = " << x << " , " << #y << " = " << y << endl;
#define Debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x, y, z)                                                        \
  cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y   \
       << ", " << z << ")\n";
#define Debug_arr(v, n)                                                        \
  for (int i = 0; i < n; ++i)                                                  \
    cerr << #v << "[" << i << "]"                                              \
         << " = " << v[i] << endl;
#define SET(p, v) fill((__typeof(**p) *)p, (__typeof(**p) *)p + sizeof(p), v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
// #define FILE_JUDGE
// #define TIMES
// #define LINES
// #define home
int n, dist[0][100005];
vector<int> v[100005];
bool used[100005];
void bfs(int x, int *Dist) {
  memset(used, 0, sizeof(used));
  Dist[x] = 0;
  used[x] = true;
  queue<int> q;
  q.push(x);
  while (q.size()) {
    int cur = q.front();
    q.pop();
    int d = Dist[cur];
    for (auto &y : v[cur]) {
      if (!used[y]) {
        Dist[y] = d + 1;
        q.push(y);
        used[y] = true;
      }
    }
  }
}
int main() {
#ifdef FILE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfs(1, dist[0]);
  bfs(n, dist[1]);
  //	for (int i=1;i<=n;++i) printf("%d%c",dist[0][i]," \n"[i==n]);
  //	for (int i=1;i<=n;++i) printf("%d%c",dist[1][i]," \n"[i==n]);
  //	puts("");
  int black = 0;
  for (int i = 2; i <= n - 1; ++i) {
    if (dist[0][i] <= dist[1][i]) {
      ++black;
    }
  }
  int white = n - 2 - black;
  if (black > white) {
    puts("Fennec");
  } else {
    puts("Snuke");
  }
#ifdef TIMES
  eprintf("Times = %d ms.\n", clock());
#endif
#ifdef LINES
  eprintf("lines : %d line.\n", __LINE__ + 3);
#endif
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x, y)                                                          \
  cerr << #x << " = " << x << " , " << #y << " = " << y << endl;
#define Debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x, y, z)                                                        \
  cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y   \
       << ", " << z << ")\n";
#define Debug_arr(v, n)                                                        \
  for (int i = 0; i < n; ++i)                                                  \
    cerr << #v << "[" << i << "]"                                              \
         << " = " << v[i] << endl;
#define SET(p, v) fill((__typeof(**p) *)p, (__typeof(**p) *)p + sizeof(p), v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
// #define FILE_JUDGE
// #define TIMES
// #define LINES
// #define home
int n, dist[2][100005];
vector<int> v[100005];
bool used[100005];
void bfs(int x, int *Dist) {
  memset(used, 0, sizeof(used));
  Dist[x] = 0;
  used[x] = true;
  queue<int> q;
  q.push(x);
  while (q.size()) {
    int cur = q.front();
    q.pop();
    int d = Dist[cur];
    for (auto &y : v[cur]) {
      if (!used[y]) {
        Dist[y] = d + 1;
        q.push(y);
        used[y] = true;
      }
    }
  }
}
int main() {
#ifdef FILE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bfs(1, dist[0]);
  bfs(n, dist[1]);
  //	for (int i=1;i<=n;++i) printf("%d%c",dist[0][i]," \n"[i==n]);
  //	for (int i=1;i<=n;++i) printf("%d%c",dist[1][i]," \n"[i==n]);
  //	puts("");
  int black = 0;
  for (int i = 2; i <= n - 1; ++i) {
    if (dist[0][i] <= dist[1][i]) {
      ++black;
    }
  }
  int white = n - 2 - black;
  if (black > white) {
    puts("Fennec");
  } else {
    puts("Snuke");
  }
#ifdef TIMES
  eprintf("Times = %d ms.\n", clock());
#endif
#ifdef LINES
  eprintf("lines : %d line.\n", __LINE__ + 3);
#endif
  return 0;
}