Language: C++

#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        for(auto it = v[x].begin();v[x].end();it++)
        {
            ans = ans + dfs[it];
        }
    }
    return ans;
}
int main()
{
    ll n,m;
    cin>>n>>m;
    fi(i,m)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans = 0;
    fi(i,n)
    {
        if(visited[i]==0)
        {
            ans = max(ans,dfs[i]);
        }
    }
    cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int dfs(int)':
a.cc:39:44: error: could not convert '(& v.std::vector<std::vector<int> >::operator[](((std::vector<std::vector<int> >::size_type)x)))->std::vector<int>::end()' from 'std::vector<int>::iterator' to 'bool'
   39 |         for(auto it = v[x].begin();v[x].end();it++)
      |                                    ~~~~~~~~^~
      |                                            |
      |                                            std::vector<int>::iterator
a.cc:41:28: error: no match for 'operator[]' (operand types are 'int(int)' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >')
   41 |             ans = ans + dfs[it];
      |                            ^
a.cc: In function 'int main()':
a.cc:64:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   64 |             ans = max(ans,dfs[i]);
      |                                ^
a.cc:64:22: error: no matching function for call to 'max(ll&, int (&)(int))'
   64 |             ans = max(ans,dfs[i]);
      |                   ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:64:22: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int(int)')
   64 |             ans = max(ans,dfs[i]);
      |                   ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:64:22: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   64 |             ans = max(ans,dfs[i]);
      |                   ~~~^~~~~~~~~~~~