Problem p02762 (C++)

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int n;
vvi F;    // n 頂点 m 辺のグラフ: 友達関係
vvi B;    // n 頂点 k 辺のグラフ: ブロック関係
vi color; // グラフ F について同じ連結成分にいる頂点には同じ色をあてる
// vector<bool> seen;

void dfs(int v, int c) {
  color[v] = c;
  for (auto u : F[v]) {
    if (color[u] != -1)
      continue;
    dfs(u, c);
  }
}

void Main() {
  int m, k;
  cin >> n >> m >> k;
  if (m == 0) {
    rep(i, n) cout << 0 << " ";
    return;
  }
  F.resize(n);
  color.resize(n, -1);
  // seen.resize(n, false);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    F[a].push_back(b);
    F[b].push_back(a);
  }

  // vi ans(n);
  int c = 1;
  rep(i, m) {
    if (color[i] != -1)
      continue;
    dfs(i, c);
    c++;
  }

  /*
  rep(i,n) {
  cout << color[i] << " ";
}
//*/

  vi cnt(c, 0); // cnt[0] は使わない
  rep(i, n) { cnt[color[i]]++; }

  /*
  rep(i,c){
  cout << cnt[i] << " ";
}
  //*/

  /*
      rep(i,n){
      cout << cnt[color[i]] << " ";
  }
      //*/

  B.resize(n);

  rep(i, k) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (color[a] == color[b]) {
      B[a].push_back(b);
      B[b].push_back(a);
    }
  }

  /*
  rep(i,n){
  // for(auto u:B[i]) cout << i << " " << u << endl;
  cout << B[i].size() << endl;
  }
*/

  rep(i, n) { cout << cnt[color[i]] - 1 - F[i].size() - B[i].size() << " "; }
  cout << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

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

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

int n;
vvi F;    // n 頂点 m 辺のグラフ: 友達関係
vvi B;    // n 頂点 k 辺のグラフ: ブロック関係
vi color; // グラフ F について同じ連結成分にいる頂点には同じ色をあてる
// vector<bool> seen;

void dfs(int v, int c) {
  color[v] = c;
  for (auto u : F[v]) {
    if (color[u] != -1)
      continue;
    dfs(u, c);
  }
}

void Main() {
  int m, k;
  cin >> n >> m >> k;
  if (m == 0) {
    rep(i, n) cout << 0 << " ";
    return;
  }
  F.resize(n);
  color.resize(n, -1);
  // seen.resize(n, false);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    F[a].push_back(b);
    F[b].push_back(a);
  }

  // vi ans(n);
  int c = 1;
  rep(i, n) {
    if (color[i] != -1)
      continue;
    dfs(i, c);
    c++;
  }

  /*
  rep(i,n) {
  cout << color[i] << " ";
}
//*/

  vi cnt(c, 0); // cnt[0] は使わない
  rep(i, n) { cnt[color[i]]++; }

  /*
  rep(i,c){
  cout << cnt[i] << " ";
}
  //*/

  /*
      rep(i,n){
      cout << cnt[color[i]] << " ";
  }
      //*/

  B.resize(n);

  rep(i, k) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (color[a] == color[b]) {
      B[a].push_back(b);
      B[b].push_back(a);
    }
  }

  /*
  rep(i,n){
  // for(auto u:B[i]) cout << i << " " << u << endl;
  cout << B[i].size() << endl;
  }
*/

  rep(i, n) { cout << cnt[color[i]] - 1 - F[i].size() - B[i].size() << " "; }
  cout << endl;
  return;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}