Language: C++

#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

vector<int> visit;
void dfs(Graph &G,int x,int y){
    visit[x]=y;
    for(auto v:G[x]){
        if(visit[v]!=-1)continue;
        dfs(G,v,y);
    }
}

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    Graph g(n);
    //O(m)
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    Graph h(n);
    //O(k)
    rep(i,k){
        int c,d;
        cin>>c>>d;
        c--;d--;
        h[c].push_back(d);
        h[d].push_back(c);
    }
    //O(n)
    visit.assign(n,-1);
    int j=0;
    rep(i,n){
        if(visit[i]!=-1)continue;
        dfs(g,i,j);
        ++j;
    }
    //O(n)
    vector<int> cnt(n);
    rep(i,n){
        cnt[visit[i]]++;
    }
    vector<int> NoConnect(n,0);
    rep(i,n){
        if(h[i].size()==0)continue;
        for(auto v:h[i]){
            if(visit[i]!=visit[v]){
                NoConnect[v]++;
            }
        }
    }
    rep(i,n){
        int ans=cnt[visit[i]]-1;
        ans=ans-g[i].size()-h[i].size()+NoConnect[i];
        cout<<ans<<endl;
    }

    
}

Compiler output:
a.cc: In function 'void dfs(Graph&, int, int)':
a.cc:15:5: error: reference to 'visit' is ambiguous
   15 |     visit[x]=y;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:17:12: error: reference to 'visit' is ambiguous
   17 |         if(visit[v]!=-1)continue;
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc: In function 'int main()':
a.cc:44:5: error: reference to 'visit' is ambiguous
   44 |     visit.assign(n,-1);
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:47:12: error: reference to 'visit' is ambiguous
   47 |         if(visit[i]!=-1)continue;
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:54:13: error: reference to 'visit' is ambiguous
   54 |         cnt[visit[i]]++;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:60:16: error: reference to 'visit' is ambiguous
   60 |             if(visit[i]!=visit[v]){
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:60:26: error: reference to 'visit' is ambiguous
   60 |             if(visit[i]!=visit[v]){
      |                          ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:66:21: error: reference to 'visit' is ambiguous
   66 |         int ans=cnt[visit[i]]-1;
      |                     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~