Graphs? kruskal() { List g = getSortedPathList(); //int cost = 0; List res = []; for (int i = 0; i < _amount; i++) { res.add(Dot(_dots[i].getName(), _dots[i].num)); } List treeId = List.filled(_amount, 0); for (int i = 0; i < _amount; ++i) { treeId[i] = i; } for (int i = 0; i < g.length; ++i) { int a = g[i].d - 1, b = g[i].p - 1; int l = g[i].l; if (treeId[a] != treeId[b]) { //cost += l; res[a].addPath(b + 1, l); int oldId = treeId[b], newId = treeId[a]; for (int j = 0; j < _amount; ++j) { if (treeId[j] == oldId) { treeId[j] = newId; } } } } _dots = res; return Graphs.fromList(_name, res, _useLength, _oriented); }