Submission #674259

#TimeUsernameProblemLanguageResultExecution timeMemory
674259Jarif_RahmanDuathlon (APIO18_duathlon)C++17
0 / 100
1098 ms1048576 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int n, m; vector<vector<int>> graph; vector<int> sz; ll ans = 0; int N = 0; void dfs(int nd, int ss){ N++; sz[nd] = 1; for(int x: graph[nd]) if(x != ss) dfs(x, nd), sz[nd]+=sz[x]; } void dfs2(int nd, int ss){ for(int x: graph[nd]) if(x != ss) dfs2(x, nd); ans+=ll(N-sz[nd])*ll(sz[nd]-1); for(int x: graph[nd]) if(x != ss) ans+=ll(N-sz[x]-1)*ll(sz[x]); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; graph.resize(n); sz.resize(n, 0); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; graph[a].pb(b); graph[b].pb(a); } for(int i = 0; i < 1; i++) if(!sz[i]){ N = 0; dfs(i, -1); dfs2(i, -1); } cout << ans << "\n"; }
#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...