Submission #145548

#TimeUsernameProblemLanguageResultExecution timeMemory
145548surface03비용 (KOI11_cost)C++14
24 / 24
57 ms4088 KiB
#include<bits/stdc++.h> using namespace std; using LL=long long; const LL MOD=(int)1e9; const int LM=(int)1e5+1; int N,M,G[LM],cnt[LM]; LL sum,ans; struct data{ int s,e,w; bool operator<(const data&r)const{ return w>r.w; } }A[LM]; void input(){ scanf("%d%d",&N,&M); for(int i=1;i<=N;i++){ G[i]=i; cnt[i]=1; } for(int i=0;i<M;i++){ scanf("%d%d%d",&A[i].s,&A[i].e,&A[i].w); sum+=A[i].w; } sort(A,A+M); } int Find(int n){ if(G[n]==n)return n; return G[n]=Find(G[n]); } void Union(int s,int e){ s=Find(s),e=Find(e); if(s==e)return; ans=(ans+sum*cnt[s]*cnt[e])%MOD; G[s]=e; cnt[e]+=cnt[s]; } int main(){ input(); for(int i=0;i<M;i++){ Union(A[i].s,A[i].e); sum-=A[i].w; } printf("%lld\n",ans); }

Compilation message (stderr)

cost.cpp: In function 'void input()':
cost.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~
cost.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d",&A[i].s,&A[i].e,&A[i].w);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...