Submission #22576

#TimeUsernameProblemLanguageResultExecution timeMemory
22576↓우리보다잘하는팀 (#40)Logistical Metropolis (KRIII5_LM)C++98
2 / 7
96 ms1180 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...