// n vertex, m edges, construct forest intkruskal(){ sort(e, e + m, cmp); for (int i = 0; i <= n;i++){ f[i] = i; } int ans = 0; int cnt = 0; for (int i = 0; i < m;i++){ int u = e[i].u; int v = e[i].v; int d = e[i].d; u = find(u); v = find(v); if(u != v){ f[u] = v; ans += d; cnt++; } } return ans; }