This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int DIM = 1E5+7;
const int INF = 1E9;
vector<int> G[DIM];
int depth[DIM];
ll res = 0;
int dfs(int v,int par){
depth[v] = depth[par]+1;
vector<int> V;
for(int to:G[v]){
if (depth[to]!=0 && depth[to]<depth[v]) {
V.push_back(depth[to]);
res+=(depth[v]-depth[to]-1);
continue;
}
if (!depth[to])
dfs(to,v);
}
sort(V.begin(),V.end());
V.push_back(depth[v]-1);
for(int i = int(V.size())-2;i>=0;--i){
res+=ll(V[i])*(V[i+1]-V[i]);
}
res+=ll(depth[v]-1)*(depth[v]-2)/2;
return 1;
}
int solve(){
int n,m;
cin>>n>>m;
for(int i = 1;i<=m;++i){
ll u,v;
cin>>u>>v;
G[u].push_back(v);
G[v].push_back(u);
}
for(int i = 1;i<=n;++i){
if (!depth[i])
dfs(i,i);
}
cout<<res*2<<endl;
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# | 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... |