#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
struct node{
int u,v,w;
friend bool operator < (node a, node b)
{
return a.w > b.w;
}
};
priority_queue<node>q;
int f[1010];
int find(int x)
{
return f[x] == x ? x : f[x] = find(f[x]);
}
node now;
int main()
{
int n,m,k;
cin>>n>>m>>k;
for(int i = 1; i <= n; i++) f[i] = i;
while(m--)
{
int x,y,l;
cin>>x>>y>>l;
now.u = x;
now.v = y;
now.w = l;
q.push(now);
}
int cnt = 0;
int ans = 0;
while(cnt < n-k)
{
if(q.size())
{
now = q.top();
q.pop();
}
if(find(now.u) != find(now.v))
{
cnt++;
f[find(now.u)] = find(now.v);
ans += now.w;
}
}
if(cnt < n-k)
{
cout<<"No Answer"<<endl;
}
else
cout<<ans<<endl;
}
P1195 口袋的天空
最新推荐文章于 2023-08-07 16:16:44 发布