# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103703 | autumn_eel | Duathlon (APIO18_duathlon) | C++14 | 151 ms | 12104 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];
bool used1[200000],used2[200000];
ll ans=0;
int cnt=0;
void dfs1(int v){
cnt++;
used1[v]=true;
for(int u:E[v]){
if(used1[u])continue;
dfs1(u);
}
}
void dfs2(int v,int p){
used2[v]=true;
int s=cnt-1;
sz[v]=1;
for(int u:E[v]){
if(used2[u])continue;
dfs2(u,v);
sz[v]+=sz[u];
s-=sz[u];
ans+=sz[u]*(ll)(cnt-sz[u]-1);
}
ans+=s*(ll)(cnt-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);
}
rep(i,n){
if(!used1[i]){
cnt=0;
dfs1(i);
dfs2(i,-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... |