Problem p03660 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <string>
#include <vector>

#include <inttypes.h>
using namespace std;

int main() {
  int32_t N;
  scanf("%d", &N);

#define MAX_N (10000)
  vector<int32_t> graph[MAX_N];
  for (int32_t i = 0; i < N - 1; i++) {
    int32_t a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  bool used[MAX_N];
  int32_t dist_a[MAX_N], dist_b[MAX_N];
  for (int32_t i = 0; i < N; i++) {
    dist_a[i] = dist_b[i] = numeric_limits<int32_t>::max();
    used[i] = false;
  }

  // 0 to N - 1 (distance)
  dist_a[0] = 0;
  priority_queue<int32_t, vector<int32_t>, greater<int32_t>> q;
  q.push(0);
  while (!q.empty()) {
    int32_t node = q.top();
    q.pop();
    if (used[node])
      continue;

    used[node] = true;
    for (size_t i = 0; i < graph[node].size(); i++) {
      int32_t next = graph[node][i];
      if (dist_a[next] > dist_a[node] + 1) {
        dist_a[next] = dist_a[node] + 1;
        q.push(next);
      }
    }
  }

  // N - 1 to 0 (distance)
  for (int32_t i = 0; i < N; i++)
    used[i] = false;
  dist_b[N - 1] = 0;
  q.push(N - 1);
  while (!q.empty()) {
    int32_t node = q.top();
    q.pop();
    if (used[node])
      continue;

    used[node] = true;
    for (size_t i = 0; i < graph[node].size(); i++) {
      int32_t next = graph[node][i];
      if (dist_b[next] > dist_b[node] + 1) {
        dist_b[next] = dist_b[node] + 1;
        q.push(next);
      }
    }
  }

  int32_t whiteCnt = 0;
  for (int32_t i = 0; i < N; i++)
    if (dist_a[i] > dist_b[i])
      whiteCnt++;

  printf("%s\n", N - whiteCnt > whiteCnt ? "Fennec" : "Snuke");

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <string>
#include <vector>

#include <inttypes.h>
using namespace std;

int main() {
  int32_t N;
  scanf("%d", &N);

#define MAX_N (100000)
  vector<int32_t> graph[MAX_N];
  for (int32_t i = 0; i < N - 1; i++) {
    int32_t a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  bool used[MAX_N];
  int32_t dist_a[MAX_N], dist_b[MAX_N];
  for (int32_t i = 0; i < N; i++) {
    dist_a[i] = dist_b[i] = numeric_limits<int32_t>::max();
    used[i] = false;
  }

  // 0 to N - 1 (distance)
  dist_a[0] = 0;
  priority_queue<int32_t, vector<int32_t>, greater<int32_t>> q;
  q.push(0);
  while (!q.empty()) {
    int32_t node = q.top();
    q.pop();
    if (used[node])
      continue;

    used[node] = true;
    for (size_t i = 0; i < graph[node].size(); i++) {
      int32_t next = graph[node][i];
      if (dist_a[next] > dist_a[node] + 1) {
        dist_a[next] = dist_a[node] + 1;
        q.push(next);
      }
    }
  }

  // N - 1 to 0 (distance)
  for (int32_t i = 0; i < N; i++)
    used[i] = false;
  dist_b[N - 1] = 0;
  q.push(N - 1);
  while (!q.empty()) {
    int32_t node = q.top();
    q.pop();
    if (used[node])
      continue;

    used[node] = true;
    for (size_t i = 0; i < graph[node].size(); i++) {
      int32_t next = graph[node][i];
      if (dist_b[next] > dist_b[node] + 1) {
        dist_b[next] = dist_b[node] + 1;
        q.push(next);
      }
    }
  }

  int32_t whiteCnt = 0;
  for (int32_t i = 0; i < N; i++)
    if (dist_a[i] > dist_b[i])
      whiteCnt++;

  printf("%s\n", N - whiteCnt > whiteCnt ? "Fennec" : "Snuke");

  return 0;
}