标签:
/* Author: JDD PROG: bzoj1083 繁忙的都市 DATE: 2015.9.22 */ #include <cstdio> #include <algorithm> #define REP(i, s, n) for(int i = s; i <= n; i ++) #define REP_(i, s, n) for(int i = n; i >= s; i --) #define MAX_N 305 using namespace std; struct node{ int u, v, w; }E[MAX_N * MAX_N >> 1]; int n, m; void init() { scanf("%d%d", &n, &m); REP(i, 1, m) scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w); } int F[MAX_N]; bool cmp(node a, node b) { return a.w < b.w; } #define max(a, b) (a > b ? a : b) int find(int x) { if(F[x] == x) return x; return F[x] = find(F[x]); } void doit() { int ans = 0; REP(i, 1, n) F[i] = i; sort(E + 1, E + m + 1, cmp); REP(i, 1, m){ int rx = find(E[i].u), ry = find(E[i].v); if(rx == ry) continue; F[ry] = rx; ans = max(ans, E[i].w); } printf("%d %d\n", n - 1, ans); } int main() { init(); doit(); return 0; }
标签:
原文地址:http://www.cnblogs.com/ALXPCUN/p/4830157.html