inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
intKruskal(){ int ret = -1; int treeAns = 0; sort(edge + 1, edge + 1 + m, sortCmp); for (int i = 1; i <= MAXN; ++i) U[i] = i; for (int i = 1; i <= m; ++i) { int eprev = Find(edge[i].prev); int enext = Find(edge[i].next); if (eprev == enext) continue; treeAns += edge[i].w; U[eprev] = enext; ret = max(ret, edge[i].w); // 更新权值 ++cntTree; if (cntTree == n - 1) break; } return ret; }
intmain(int argc, char *const argv[]){ n = getint(), m = getint(); for (int i = 1; i <= m; ++i) { int v = getint(), next = getint(), w = getint(); edge[i].prev = v; edge[i].next = next; edge[i].w = w; } int ans = Kruskal(); printf("%d %d", n - 1, ans); // 显而易见,生成的树肯定有 n - 1 条边,所以直接输出 n - 1 就好 return0; }