Problem p02762 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

int N, M, K;
vector<vector<int>> graph;
vector<int> group;
vector<int> group_count;
vector<vector<int>> block;

int main() {
  cin >> N >> M >> K;
  graph.resize(N);
  block.resize(N);
  group.resize(N);
  group_count.resize(N);
  rp(i, 0, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    graph.at(a).emplace_back(b);
    graph.at(b).emplace_back(a);
  }
  rp(i, 0, K) {
    int c, d;
    scanf("%d%d", &c, &d);
    c--;
    d--;
    block.at(c).emplace_back(d);
    block.at(d).emplace_back(c);
  }

  int g = 1;
  rp(i, 0, N) {
    if (group.at(i) == 0) {
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int s = q.front();
        q.pop();
        if (group.at(s) == 0) {
          group.at(s) = g;
          group_count.at(g)++;
          for (auto x : graph.at(s)) {
            if (group[x] == 0)
              q.push(x);
          }
        }
      }
      g++;
    }
  }

  rp(i, 0, N) {
    int res = group_count[group[i]] - 1 - int(graph[i].size());
    for (auto x : block[i]) {
      if (group[i] == group[x])
        res--;
    }
    printf("%d ", res);
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI = 3.14159265358979323846;

int N, M, K;
vector<vector<int>> graph;
vector<int> group;
vector<int> group_count;
vector<vector<int>> block;

int main() {
  cin >> N >> M >> K;
  graph.resize(N);
  block.resize(N);
  group.resize(N);
  group_count.resize(N + 10);
  rp(i, 0, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    graph.at(a).emplace_back(b);
    graph.at(b).emplace_back(a);
  }
  rp(i, 0, K) {
    int c, d;
    scanf("%d%d", &c, &d);
    c--;
    d--;
    block.at(c).emplace_back(d);
    block.at(d).emplace_back(c);
  }

  int g = 1;
  rp(i, 0, N) {
    if (group.at(i) == 0) {
      queue<int> q;
      q.push(i);
      while (!q.empty()) {
        int s = q.front();
        q.pop();
        if (group.at(s) == 0) {
          group.at(s) = g;
          group_count.at(g)++;
          for (auto x : graph.at(s)) {
            if (group[x] == 0)
              q.push(x);
          }
        }
      }
      g++;
    }
  }

  rp(i, 0, N) {
    int res = group_count[group[i]] - 1 - int(graph[i].size());
    for (auto x : block[i]) {
      if (group[i] == group[x])
        res--;
    }
    printf("%d ", res);
  }
  cout << endl;
  return 0;
}