10std::array<ll, mx> parent;
12std::vector<std::pair<ll, std::pair<ll, ll>>> edges;
14 for (
int i = 0; i <
node + edge; ++i) {
20 while (parent[i] != i) {
21 parent[i] = parent[parent[i]];
27void join(
int x,
int y) {
30 parent[root_x] = root_y;
35 for (
int i = 0; i < edge; ++i) {
36 ll x = edges[i].second.first;
37 ll y = edges[i].second.second;
38 if (root(x) != root(y)) {
39 mincost += edges[i].first;
48 int from = 0, to = 0, cost = 0, totalcost = 0;
49 std::cin >>
node >> edge;
50 if (
node == 0 && edge == 0) {
54 for (
int i = 0; i < edge; ++i) {
55 std::cin >> from >> to >> cost;
56 edges.emplace_back(make_pair(cost, std::make_pair(from, to)));
59 sort(edges.begin(), edges.end());
60 std::cout << kruskal() << std::endl;