Submission #22576

# Submission time Handle Problem Language Result Execution time Memory
22576 2017-04-30T05:40:26 Z ↓우리보다잘하는팀(#947, ainta, gs12117, gs13068) Logistical Metropolis (KRIII5_LM) C++
2 / 7
96 ms 1180 KB
#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

LM.cpp: In function 'int main()':
LM.cpp:37:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
LM.cpp:40:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&w[i].a,&w[i].b,&w[i].c);
                                                ^
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1180 KB Output is correct
2 Correct 79 ms 1180 KB Output is correct
3 Correct 79 ms 1180 KB Output is correct
4 Correct 76 ms 1180 KB Output is correct
5 Correct 83 ms 1180 KB Output is correct
6 Correct 86 ms 1180 KB Output is correct
7 Correct 73 ms 1180 KB Output is correct
8 Correct 86 ms 1180 KB Output is correct
9 Correct 86 ms 1180 KB Output is correct
10 Correct 86 ms 1180 KB Output is correct
11 Correct 79 ms 1180 KB Output is correct
12 Correct 86 ms 1180 KB Output is correct
13 Correct 96 ms 1180 KB Output is correct
14 Correct 93 ms 1180 KB Output is correct
15 Correct 89 ms 1180 KB Output is correct
16 Correct 43 ms 1180 KB Output is correct
17 Correct 43 ms 1180 KB Output is correct
18 Correct 46 ms 1180 KB Output is correct
19 Correct 49 ms 1180 KB Output is correct
20 Correct 39 ms 1180 KB Output is correct
21 Correct 43 ms 1180 KB Output is correct
22 Correct 39 ms 1180 KB Output is correct
23 Correct 43 ms 1180 KB Output is correct
24 Correct 46 ms 1180 KB Output is correct
25 Correct 0 ms 1180 KB Output is correct
26 Correct 0 ms 1180 KB Output is correct
27 Correct 0 ms 1180 KB Output is correct
28 Correct 16 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1180 KB Output isn't correct
2 Halted 0 ms 0 KB -