# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087755 | alexander707070 | Duathlon (APIO18_duathlon) | C++14 | 1057 ms | 1048576 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 MAXN 200007
using namespace std;
int n,m,a,b;
vector<int> v[MAXN];
long long sz[MAXN],sum[MAXN],comp[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]];
}
}
void dfs2(int x,int p,int s){
comp[x]=s;
for(int i=0;i<v[x].size();i++){
if(v[x][i]==p)continue;
dfs2(v[x][i],x,s);
}
sum[x]+=(s-sz[x])*(s-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);
}
for(int i=1;i<=n;i++){
if(sz[i]==0){
dfs(i,0);
dfs2(i,0,sz[i]);
}
}
for(int i=1;i<=n;i++){
ans+=(long long) (comp[i]-1)*(comp[i]-2)-sum[i];
}
cout<<ans<<"\n";
return 0;
}
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... |