Submission #103700

#TimeUsernameProblemLanguageResultExecution timeMemory
103700autumn_eelDuathlon (APIO18_duathlon)C++14
0 / 100
140 ms12792 KiB
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; int n,m; vector<int>E[200000]; int sz[200000]; ll ans=0; void dfs(int v,int p){ int s=n-1; sz[v]=1; for(int u:E[v]){ if(u==p)continue; dfs(u,v); sz[v]+=sz[u]; s-=sz[u]; ans+=sz[u]*(ll)(n-sz[u]-1); } ans+=s*(ll)(n-s-1); } int main(){ scanf("%d%d",&n,&m); assert(m<=n-1); rep(i,m){ int a,b;scanf("%d%d",&a,&b);a--;b--; E[a].push_back(b); E[b].push_back(a); } dfs(0,-1); cout<<ans<<endl; }

Compilation message (stderr)

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:27:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a,b;scanf("%d%d",&a,&b);a--;b--;
           ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...