#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 998244353;
struct node{
int x,y,w;
friend bool operator < (node a, node b)
{
return a.w < b.w;
}
};
priority_queue<node>q;
int f[100010];
node now;
int find(int x)
{
return f[x] == x ? x : f[x] = find(f[x]);
}
int main()
{
int n,m,k;
cin>>n>>m>>k;
for(int i = 1; i <= n; i++)f[i] = i;
while(m--)
{
int u,v,w;
cin>>u>>v>>w;
now.w = w;
now.x = u;
now.y = v;
q.push(now);
}
ll ans = 0;
int cnt = 0;
while(cnt < k)
{
now = q.top();
q.pop();
if(find(now.x) != find(now.y))
{
f[find(now.x)] = find(now.y);
cnt++;
ans += now.w;
}
}
cout<<ans<<endl;
}
P2121 拆地毯
最新推荐文章于 2022-02-18 00:01:42 发布