#include <bits/stdc++.h> using namespace std; const int N = 5010; struct node { int a, b, w; } no[N]; int n, m; int p[N]; int find(int x) { if (p[x] != x) p[x] = find(p[x]); return p[x]; } bool cmp(node x, node y) { return x.w < y.w; } int main() { while (cin >> n) { if (n =...