比较有技巧的(kruskal)
#ifdef Dubug
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
const int N = 1 << 10 ;
int n , m , k ;
int ans = 0 ;
int fa[N] ;
struct node{
int u,v,w ;
};
node a[N << 4] ;
bool cmp (node x , node y) {
return x.w < y.w ;
}
inline int find (int x) {
return x == fa[x] ? fa[x] : fa[x] = find(fa[x]) ;
}
inline void merge(int x,int y) {
fa[find(x)] = find(y) ;
}
signed main() {
n = In() , m = In() , k = In() ;
for(register int i=1;i<=n;i++) fa[i] = i ;
for(register int i=1;i<=m;i++) {
a[i].u = In() , a[i].v = In() , a[i].w = In() ;
}
sort(a+1,a+m+1,cmp) ;
int ans = 0 ;
int cnt = 0 ;
for(register int i=1;i<=m;i++) {
if(find(a[i].u) == find(a[i].v)) continue ;
merge(a[i].u , a[i].v) ;
ans += a[i].w ;
if(++ cnt == n - k) {
return printf("%d",ans),0 ;
}
}
return puts("No Answer"),0 ;
}