Submission #1123481

#TimeUsernameProblemLanguageResultExecution timeMemory
112348112345678Kronican (COCI16_kronican)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=21;

int n, k, res, dsu[nx], x, cmp;
priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> edg;

int find(int x)
{
    if (dsu[x]==x) return x;
    return dsu[x]=find(dsu[x]);
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>k;
    cmp=n;
    for (int i=1; i<=n; i++)
    {
        dsu[i]=i;
        for (int j=1; j<=n; j++)
        {
            cin>>x;
            if (i<j) edg.push({x, i, j});
        }
    }
    while (cmp>k)
    {
        auto [cst, u, v]=edg.top();
        edg.pop();
        if (find(u)!=find(v)) cmp--, dsu[find(u)]=find(v), res+=cst;
    }
    cout<<res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...