[Cpp is a little busy recently, so I don't want to write my ideas or something, so I can directly go to the code. [Cpp] # include <stdio. h> # include <stdlib. h> struct edge {int u, v, w, flag;} p [4952]; int n, m; int f [101]; int used [101]; int cmp (const void * aa, const void * bb) {return (struct edge *) aa)-> w-(struct edge *) bb)-> w ;} int find (int x) {return f [x] = x? X :( f [x] = find (f [x]);} int Kruskal () {int sum = 0, I, x, y, t = 0; for (I = 0; I <m; I ++) {x = find (p [I]. u); y = find (p [I]. v); if (x! = Y) {f [x] = y; sum + = p [I]. w; used [t] = I; t ++; if (t = N-1) break;} return sum;} int reKruskal () {int sum = 0, I, x, y, t = 0; for (I = 0; I <m; I ++) {x = find (p [I]. u); y = find (p [I]. v); if (x! = Y &&! P [I]. flag) {f [x] = y; sum + = p [I]. w; t ++; if (t = N-1) break;} return sum;} int main () {// freopen ("12.3.4.input.txt", "r ", stdin); int t, I, j, ans, tans, k, pt = 0; scanf ("% d", & t); for (I = 0; I <t; I ++) {scanf ("% d", & n, & m); for (j = 1; j <= n; j ++) f [j] = j; for (j = 0; j <n; j ++) used [j] =-1; for (j = 0; j <m; j ++) {scanf ("% d", & p [j]. u, & p [j]. v, & p [j]. w); p [j]. flag = 0;} qsort (p, m, sizeof (p [0]), cmp); ans = Kruskal (); pt = 0; for (j = 0; j <n-1; j ++) {p [used [j]. flag = 1; for (k = 1; k <= n; k ++) f [k] = k; tans = reKruskal (); p [used [j]. flag = 0; if (ans = tans & ans! = 0) {pt = 1; break;} if (pt) printf ("Not Unique! \ N "); else printf (" % d \ n ", ans);} return 0 ;}