Language: C++

Copy
#include<unordered_map>
#include<iostream>
#include<set>
#include<vector>
void print(std::vector<std::set<int>> graphs){
    for(int i=0;i<graphs.size();++i){
        for(auto a:graphs[i]){
            std::cout<<a<<",";
        }
        std::cout<<std::endl;
    }
}
int main(){
    int N,M;
    std::cin>>N>>M;
 
    std::vector<std::unordered_map<int,bool>> graphs;
    std::vector<int>A(M),B(M);
    for(int i=0;i<M;++i){
        std::cin>>A[i]>>B[i];
    }
    for(int i=0;i<M;++i){
        int gNumA=-1,gNumB=-1;
        for(int j=0;j<graphs.size();++j){
            auto itr=graphs[j].find(A[i]);
            if(itr!=graphs[j].end()){
                gNumA=j;
                break;
            }
        }
        for(int j=0;j<graphs.size();++j){
            auto itr=graphs[j].find(B[i]);
            if(itr!=graphs[j].end()){
                gNumB=j;
                break;
            }
        }
        if(gNumA!=-1 && gNumB!=-1){
            if(gNumA!=gNumB){
                if(gNumA>gNumB){
                    int swap=gNumB;
                    gNumB=gNumA;
                    gNumA=swap;
                }
                for(auto num:graphs[gNumB]){
                    // graphs[gNumA].insert(num);
                    graphs[gNumA][num.first]=1;
                }
                graphs.erase(graphs.begin()+gNumB);
            }
        }
        else if(gNumA==-1 && gNumB!=-1){
            // graphs[gNumB].insert(A[i]);
            graphs[gNumB][A[i]]=1;
        }
        else if(gNumA!=-1 && gNumB==-1){
            graphs[gNumA][B[i]]=1;
        }
        else{
            // std::set<int>buf;
            // buf.insert(A[i]);
            // buf.insert(B[i]);
            std::unordered_map<int,bool>buf;
            buf[A[i]]=1;
            buf[B[i]]=1;
            graphs.push_back(buf);
        }
    }
    int maxLen=1;
    for(auto g:graphs){
        if(maxLen<g.size()){
            maxLen=g.size();
        }
    }
    // print(graphs);
    std::cout<<maxLen<<std::endl;
}

Compiler output:
a.cc:1:1: error: 'Copy' does not name a type
    1 | Copy
      | ^~~~
In file included from /usr/include/c++/14/unordered_map:40,
                 from a.cc:2:
/usr/include/c++/14/initializer_list:51:15: error: 'size_t' does not name a type
   51 |       typedef size_t            size_type;
      |               ^~~~~~
/usr/include/c++/14/initializer_list:1:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | // std::initializer_list support -*- C++ -*-
/usr/include/c++/14/initializer_list:57:7: error: 'size_type' does not name a type
   57 |       size_type                 _M_len;
      |       ^~~~~~~~~
/usr/include/c++/14/initializer_list:60:54: error: 'size_type' has not been declared
   60 |       constexpr initializer_list(const_iterator __a, size_type __l)
      |                                                      ^~~~~~~~~
/usr/include/c++/14/initializer_list:68:17: error: 'size_type' does not name a type
   68 |       constexpr size_type
      |                 ^~~~~~~~~
/usr/include/c++/14/initializer_list:45:11: fatal error: definition of 'class std::initializer_list<_E>' does not match '#include <initializer_list>'
   45 |     class initializer_list
      |           ^~~~~~~~~~~~~~~~
compilation terminated.