# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
145547 | surface03 | 비용 (KOI11_cost) | C++14 | 10 ms | 632 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int LM=105;
struct data{
int a,b,w;
bool operator<(const data&r)const{
return w<r.w;
}
};
int N,ans,group[LM];
vector<data>A;
int Find(int n){
if(group[n]==n)return n;
return group[n]=Find(group[n]);
}
int main(){
scanf("%d",&N);
int i,j,w;
for(i=1;i<=N;i++)group[i]=i;
for(i=1;i<=N;i++){
for(j=1;j<=N;j++){
scanf("%d",&w);
if(i<j)A.push_back({i,j,w});
}
}
sort(A.begin(),A.end());
for(auto&obj:A){
int ag=Find(obj.a),bg=Find(obj.b);
int w=obj.w;
if(ag==bg)continue;
ans+=w;
group[bg]=ag;
}
printf("%d",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |