Language: C++

class Edge:
    def __init__(self, u, v, cost):
        self.u = u
        self.v = v
        self.cost = cost
        # self.n = n


class Coordinate:
    def __init__(self, x, y, n):
        self.x = x
        self.y = y
        self.n = n

    def __repr__(self):
        return repr((self.x, self.y))


# union find。初期化
def init(_n):
    for i in range(0, _n):
        par[i] = i
        rank[i] = 0


# 木の根を求める
def find(_x):
    if par[_x] == _x:
        return _x
    else:
        par[_x] = find(par[_x])
        return par[_x]


# 集合を併合
def unite(_x, _y):
    _x = find(_x)
    _y = find(_y)
    if _x == _y:
        return

    if rank[_x] < rank[_y]:
        par[_x] = _y
    else:
        par[_y] = _x
        if rank[_x] == rank[_y]:
            rank[_x] += 1


# 同じ集合かどうか
def same(_x, _y):
    return find(_x) == find(_y)


def comp(edge1, edge2):
    return edge1.cost < edge2.cost


def kruskal():
    sorted_edges = sorted(Edges, key=lambda edges: edges.cost)
    init(V)
    res = 0
    # for i in range(E):
    # # print("u" + str(sorted_edges[i].u) + "v" + str(sorted_edges[i].v) + "cost" + str(sorted_edges[i].cost))

    for i in range(0, E):
        tmp_edge = sorted_edges[i]
        if not same(tmp_edge.u, tmp_edge.v):
            unite(tmp_edge.u, tmp_edge.v)
            # print("tmp_edge.cost" + str(tmp_edge.cost))
            res += tmp_edge.cost

    return res


if __name__ == '__main__':
    N = int(input())
    x = []
    y = []
    Coordinates = []
    for i in range(0, N):
        tmp_x, tmp_y = list(map(int, input().split()))
        # x.append(tmp_x)
        # y.append(tmp_y)
        Coordinates.append(Coordinate(tmp_x, tmp_y, i))

    sorted_by_x = sorted(Coordinates, key=lambda coordinate: coordinate.x)
    sorted_by_y = sorted(Coordinates, key=lambda coordinate: coordinate.y)

    Edges = []
    for i in range(0, N - 1):
        cost_x = min(abs(sorted_by_x[i].x - sorted_by_x[i + 1].x), abs(sorted_by_x[i].y - sorted_by_x[i + 1].y))
        Edges.append(Edge(sorted_by_x[i].n, sorted_by_x[i + 1].n, cost_x))
        # Edges.append(Edge(sorted_by_x[i + 1].n, sorted_by_x[i].n, cost_x))
        cost_y = min(abs(sorted_by_y[i].x - sorted_by_y[i + 1].x), abs(sorted_by_y[i].y - sorted_by_y[i + 1].y))
        Edges.append(Edge(sorted_by_y[i].n, sorted_by_y[i + 1].n, cost_y))
        # Edges.append(Edge(sorted_by_y[i + 1].n, sorted_by_y[i].n, cost_y))

    par = [0 for i in range(N)]
    rank = [0 for i in range(N)]
    V = N
    E = 2 * (N - 1)

    print(kruskal())


Compiler output:
a.cc:6:11: error: invalid preprocessing directive #self
    6 |         # self.n = n
      |           ^~~~
a.cc:19:3: error: invalid preprocessing directive #union
   19 | # union find。初期化
      |   ^~~~~
a.cc:19:9: error: extended character 。 is not valid in an identifier
   19 | # union find。初期化
      |         ^
a.cc:26:3: error: invalid preprocessing directive #\U00006728\U0000306e\U00006839\U00003092\U00006c42\U00003081\U0000308b
   26 | # 木の根を求める
      |   ^~~~~~~~~~~~~~
a.cc:35:3: error: invalid preprocessing directive #\U000096c6\U00005408\U00003092\U00004f75\U00005408
   35 | # 集合を併合
      |   ^~~~~~~~~~
a.cc:50:3: error: invalid preprocessing directive #\U0000540c\U00003058\U000096c6\U00005408\U0000304b\U00003069\U00003046\U0000304b
   50 | # 同じ集合かどうか
      |   ^~~~~~~~~~~~~~~~
a.cc:63:7: error: invalid preprocessing directive #for
   63 |     # for i in range(E):
      |       ^~~
a.cc:64:7: error: invalid preprocessing directive ##
   64 |     # # print("u" + str(sorted_edges[i].u) + "v" + str(sorted_edges[i].v) + "cost" + str(sorted_edges[i].cost))
      |       ^
a.cc:70:15: error: invalid preprocessing directive #print
   70 |             # print("tmp_edge.cost" + str(tmp_edge.cost))
      |               ^~~~~
a.cc:76:16: warning: multi-character literal with 8 characters exceeds 'int' size of 4 bytes
   76 | if __name__ == '__main__':
      |                ^~~~~~~~~~
a.cc:83:11: error: invalid preprocessing directive #x
   83 |         # x.append(tmp_x)
      |           ^
a.cc:84:11: error: invalid preprocessing directive #y
   84 |         # y.append(tmp_y)
      |           ^
a.cc:94:11: error: invalid preprocessing directive #Edges
   94 |         # Edges.append(Edge(sorted_by_x[i + 1].n, sorted_by_x[i].n, cost_x))
      |           ^~~~~
a.cc:97:11: error: invalid preprocessing directive #Edges
   97 |         # Edges.append(Edge(sorted_by_y[i + 1].n, sorted_by_y[i].n, cost_y))
      |           ^~~~~
a.cc:2:9: error: expected class-name before '__init__'
    2 |     def __init__(self, u, v, cost):
      |         ^~~~~~~~
a.cc:2:9: error: expected '{' before '__init__'
a.cc:2:18: error: 'self' was not declared in this scope
    2 |     def __init__(self, u, v, cost):
      |                  ^~~~
a.cc:2:24: error: 'u' was not declared in this scope
    2 |     def __init__(self, u, v, cost):
      |                        ^
a.cc:2:27: error: 'v' was not declared in this scope
    2 |     def __init__(self, u, v, cost):
      |                           ^
a.cc:2:30: error: 'cost' was not declared in this scope; did you mean 'const'?
    2 |     def __init__(self, u, v, cost):
      |                              ^~~~
      |                              const
a.cc:2:34: error: expression list treated as compound expression in initializer [-fpermissive]
    2 |     def __init__(self, u, v, cost):
      |                                  ^