# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22576 | ↓우리보다잘하는팀 (#40) | Logistical Metropolis (KRIII5_LM) | C++98 | 96 ms | 1180 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<cstdio>
#include<algorithm>
using namespace std;
int n, m;
struct point{
int a, b, c;
bool operator<(const point &p)const{
return c<p.c;
}
}w[5000];
int UF[1010], sum;
int Find(int a){
if(a==UF[a])return a;
return UF[a] = Find(UF[a]);
}
void Merge(int a, int b, int c){
a = Find(a), b = Find(b);
if(a!=b){
sum += c;
UF[a] = b;
}
}
int Calc(int a){
int i;
sum = 0;
for(i=1;i<=n;i++)UF[i]=i;
for(i=0;i<m;i++){
if(w[i].a==a||w[i].b==a){
Merge(w[i].a,w[i].b,w[i].c);
}
}
for(i=0;i<m;i++)Merge(w[i].a,w[i].b,w[i].c);
return sum;
}
int main(){
int i;
scanf("%d%d",&n,&m);
if(n>1000||m>3000)return 0;
for(i=0;i<m;i++){
scanf("%d%d%d",&w[i].a,&w[i].b,&w[i].c);
}
sort(w,w+m);
for(i=1;i<=n;i++){
printf("%d\n",Calc(i));
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |