Submission #1087744

#TimeUsernameProblemLanguageResultExecution timeMemory
1087744alexander707070Duathlon (APIO18_duathlon)C++14
0 / 100
1092 ms1048576 KiB
#include<bits/stdc++.h> #define MAXN 1000007 using namespace std; int n,m,a,b; vector<int> v[MAXN]; long long sz[MAXN],sum[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]]; } sum[x]+=(n-sz[x])*(n-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); } dfs(1,0); for(int i=1;i<=n;i++){ ans+=(n-2)*(n-1)-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++){
      |                 ~^~~~~~~~~~~~
#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...