Language: C++


#include<bits/stdc++.h>

using namespace std;

struct edge{
        int u, v, cost;
};

struct node{
        int x, y, id;
};

int pare[100000];
int trank[100000];

bool xcomp(node& x, node& y){
        return x.x<y.x;
}
bool ycomp(node& x, node& y){
        return x.y<y.y;
}
bool ccomp(edge& x, edge& y){
        return x.cost<y.cost;
}


int find(int u){
        if(u==pare[u])
                return u;
        return pare[u]=find(pare[u]);
}

void unite(int u, int v){
        u=find(u);
        v=find(v);
        if(u==v)
                return;
        if(trank[u]<trank[v]){
                pare[u]=v;
        }
        else{
                pare[v]=u;
                if(trank[u]==trank[v]){
                        trank[u]++;
                }
        }
        return;
}


int main(){
        int N;
        cin>>N;
        vector <edge> edge;
        vector <node> node;
        for(int i=0;i<N;i++){
                int x, y;
                cin>>x>>y;
                node n;
                n.x=x;n.y=y;n.id=i;
                node.push_back(n);
                pare[i]=i;
                trank[i]=0;
        }
        sort(node.begin(), node.end(), xcomp);
        for(int i=0;i<N-1;i++){
                edge e;
                e.u=node[i].id;
                e.v=node[i+1].id;
                e.cost=node[i+1].x-node[i].x;
        }
        sort(node.begin(), node.end(), ycomp);
        for(int i=0;i<N-1;i++){
                Edge e;
                e.u=node[i].id;
                e.v=node[i+1].id;
                e.cost=node[i+1].y-node[i].y;
                edge.push_back(e);
        }
        sort(edge.begin(), edge.end(), ccomp);
        long long res=0;
        for(int i=0;i<(int)edge.size();i++){
                edge e=edge[i];
                if(find(e.u)!=find(e.v)){
                        ans+=e.cost;
                        unite(e.u, e.v);
                }
        }
        cout<<res<<endl;
        return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:60:21: error: expected ';' before 'n'
   60 |                 node n;
      |                     ^~
      |                     ;
a.cc:61:17: error: 'n' was not declared in this scope
   61 |                 n.x=x;n.y=y;n.id=i;
      |                 ^
a.cc:68:21: error: expected ';' before 'e'
   68 |                 edge e;
      |                     ^~
      |                     ;
a.cc:69:17: error: 'e' was not declared in this scope
   69 |                 e.u=node[i].id;
      |                 ^
a.cc:75:17: error: 'Edge' was not declared in this scope; did you mean 'edge'?
   75 |                 Edge e;
      |                 ^~~~
      |                 edge
a.cc:76:17: error: 'e' was not declared in this scope
   76 |                 e.u=node[i].id;
      |                 ^
a.cc:84:21: error: expected ';' before 'e'
   84 |                 edge e=edge[i];
      |                     ^~
      |                     ;
a.cc:85:25: error: 'e' was not declared in this scope
   85 |                 if(find(e.u)!=find(e.v)){
      |                         ^
a.cc:86:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   86 |                         ans+=e.cost;
      |                         ^~~
      |                         abs