# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
408028 | juggernaut | Duathlon (APIO18_duathlon) | C++17 | 1122 ms | 1048580 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>
using namespace std;
#define endl '\n'
typedef long long ll;
int n,m;
int sz[100005];
vector<int>g[100005];
void dfs(int v,int p){
sz[v]=1;
for(int to:g[v])if(to!=p){
dfs(to,v);
sz[v]+=sz[to];
}
}
int root;
ll ans=0;
void calc(int v,int p){
ll sum=0;
vector<int>vec;
for(int to:g[v])if(to!=p)vec.push_back(sz[to]);
if(root^v)vec.push_back(sz[root]-sz[v]);
for(int x:vec)sum+=x;
for(int x:vec){
sum-=x;
ans+=1ll*x*sum;
sum+=x;
}
for(int to:g[v])if(to!=p)calc(to,v);
}
int main(){
scanf("%d%d",&n,&m);
while(m--){
int x,y;
scanf("%d%d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
for(root=1;root<=n;root++)if(!sz[root])dfs(root,root),calc(root,root);
printf("%lld",ans);
}
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... |