# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103700 | autumn_eel | Duathlon (APIO18_duathlon) | C++14 | 140 ms | 12792 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |