Submission #1114526

#TimeUsernameProblemLanguageResultExecution timeMemory
1114526asli_bgDuathlon (APIO18_duathlon)C++11
0 / 100
49 ms33096 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define all(x) x.begin(),x.end() #define sp <<' '<< #define pb push_back #define FOR(i,a) for(int i=0;i<(a);i++) #define FORE(i,a,b) for(int i=(a);i<(b);i++) #define cont(a) for(auto el:a) cout<<el<<' '; cout<<endl; #define contp(a) for(auto el:a) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl; #define DEBUG(x) cout<<#x sp ":" sp x<<endl; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; typedef long long ll; #define endl '\n' #define mid (l+r)/2 const int MAXN=2e5+5; int n,m; vi adj[MAXN]; int low[MAXN], dep[MAXN], sub[MAXN], leaf[MAXN]; bool vis[MAXN]; int ans; int back; int tut[MAXN]; void dfs(int nd,int ata,int h){ dep[nd]=h; sub[nd]=0; low[nd]=h; multiset<int> s; for(auto kom:adj[nd]){ if(kom==ata) continue; if(vis[kom]) continue; vis[kom]=true; dfs(kom,nd,h+1); sub[nd]+=sub[kom]; s.insert(sub[kom]); } int kalan=n-sub[nd]-1; s.insert(kalan); int ekle=0; for(auto el:s) ekle+=(n-1-el)*el; //subtreeler arası ans+=ekle; sub[nd]++; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>m; FOR(i,m){ int a,b; cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } ans=0; back=0; vis[1]=true; dfs(1,-1,0); cout<<ans<<endl; }
#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...