Submission #1087755

#TimeUsernameProblemLanguageResultExecution timeMemory
1087755alexander707070Duathlon (APIO18_duathlon)C++14
23 / 100
1057 ms1048576 KiB
#include<bits/stdc++.h> #define MAXN 200007 using namespace std; int n,m,a,b; vector<int> v[MAXN]; long long sz[MAXN],sum[MAXN],comp[MAXN],ans; void dfs(int x,int p){ sz[x]=1; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; dfs(v[x][i],x); sum[x]+=sz[v[x][i]]*(sz[v[x][i]]-1); sz[x]+=sz[v[x][i]]; } } void dfs2(int x,int p,int s){ comp[x]=s; for(int i=0;i<v[x].size();i++){ if(v[x][i]==p)continue; dfs2(v[x][i],x,s); } sum[x]+=(s-sz[x])*(s-sz[x]-1); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=1;i<=m;i++){ cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } for(int i=1;i<=n;i++){ if(sz[i]==0){ dfs(i,0); dfs2(i,0,sz[i]); } } for(int i=1;i<=n;i++){ ans+=(long long) (comp[i]-1)*(comp[i]-2)-sum[i]; } cout<<ans<<"\n"; return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs2(int, int, int)':
count_triplets.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
#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...