Problem p02762 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
struct edge {
  int from, to, cost;
};
struct Union {
  vector<int> par;
  Union(int n) { par = vector<int>(n, -1); }
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  int Size(int a) { return -par[find(a)]; }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
      return;
    if (Size(b) > Size(a))
      swap<int>(a, b);
    par[a] += par[b];
    par[b] = a;
  }
  int much(int a) {
    vector<int> e(a);
    rep(i, a) e[i] = find(i);
    sort(all(e));
    e.erase(unique(all(e)), e.end());
    return e.size();
  }
};
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> d(b), e(b), f(c), g(c);
  rep(i, b) cin >> d[i] >> e[i];
  rep(i, c) cin >> f[i] >> g[i];
  Union l(a);
  vector<int> n(a, 0), m(a, 0);
  rep(i, b) {
    l.unite(d[i] - 1, e[i] - 1);
    n[d[i] - 1]++;
    n[e[i] - 1]++;
  }
  rep(i, c) {
    if (l.same(f[i], g[i])) {
      m[f[i] - 1]++;
      m[g[i] - 1]++;
    }
  }
  rep(i, a) { cout << l.Size(i) - n[i] - 1 - m[i] << ' '; }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define rep2(i, n) for (int i = 0; i <= n; i++)
#define repr(i, a, n) for (int i = a; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
#define vector2(a, b, c)                                                       \
  vector<vector<int>> a(b /*縦！w*/, vector<int>(c /*横！w*/))
#define INF 1e10
#define MOD 1e9 + 7
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<int>>;
struct edge {
  int from, to, cost;
};
struct Union {
  vector<int> par;
  Union(int n) { par = vector<int>(n, -1); }
  int find(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = find(par[x]);
  }
  bool same(int a, int b) { return find(a) == find(b); }
  int Size(int a) { return -par[find(a)]; }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b)
      return;
    if (Size(b) > Size(a))
      swap<int>(a, b);
    par[a] += par[b];
    par[b] = a;
  }
  int much(int a) {
    vector<int> e(a);
    rep(i, a) e[i] = find(i);
    sort(all(e));
    e.erase(unique(all(e)), e.end());
    return e.size();
  }
};
signed main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> d(b), e(b), f(c), g(c);
  rep(i, b) cin >> d[i] >> e[i];
  rep(i, c) cin >> f[i] >> g[i];
  Union l(a);
  vector<int> n(a, 0), m(a, 0);
  rep(i, b) {
    l.unite(d[i] - 1, e[i] - 1);
    n[d[i] - 1]++;
    n[e[i] - 1]++;
  }
  rep(i, c) {
    if (l.same(f[i] - 1, g[i] - 1)) {
      m[f[i] - 1]++;
      m[g[i] - 1]++;
    }
  }
  rep(i, a) { cout << l.Size(i) - n[i] - 1 - m[i] << ' '; }
}