# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759333 | Trisanu_Das | Duathlon (APIO18_duathlon) | C++17 | 0 ms | 0 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.
#incude <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, c, low[100005], dfn[100005], avsub[100005], sub[100005], st[100005], top=-1, dft, ans, c;
vector<int> adj[100005];
bool vis[100005];
void cc_cnt(int u){
vis[u] = true; c++;
for(int v : adj[u]) if(!vis[v]) cc_cnt(v);
}
void dfs(int u,int f) {
low[u]=dfn[u]=++dft,sub[u]=1,ans+=(c-1)*(c-1),avsub[u]=1,st[++top]=u;
for(int i:adj[u])
if(i!=f)
if(!dfn[i]) {
dfs(i,u),sub[u]+=sub[i];
if(low[i]>=dfn[u]) {
ll sq=0,sz=0;
avsub[u]+=sub[i];
for(int x=-1;x!=i;) x=st[top--],sq+=(ll)avsub[x]*avsub[x],++sz;
ans-=sz*((c-sub[i])*(c-sub[i])+sq);
}
else low[u]=min(low[u],low[i]);
}
else if(dfn[u]>dfn[i]) low[u]=min(low[u],dfn[i]);
}
signed main(){
cin >> n >> m;
while(m--){
int u, v; cin >> u >> v;
adj[u].push_back(v); adj[v].push_back(u);
}
for(int i=1;i<=n;++i) if(!vis[i]) c=0, cc_cnt(i), dfs(i,i);
cout << ans << "\n";
}