#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int N = 1e5+3;
vector<int> grf[N], tree[N];
int pre[N], low[N], cnt;
ll siz[N], out;
bool odw[N];
void dfs(int v, int p){
odw[v]=1;
for(auto w:grf[v]){
if(w==p) continue;
dfs(w, v);
siz[v]+=siz[w];
}
for(auto w:grf[v]){
if(w==p) continue;
out+=siz[w]*(siz[v]-siz[w]) + (siz[w])*(siz[w]-1);
}
siz[v]++;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i=0; i<m; i++){
int a, b;
cin >> a >> b;
grf[a].pb(b);
grf[b].pb(a);
}
for(int i=1; i<=n; i++){
if(odw[i]) continue;
dfs(i, i);
}
cout << out << '\n';
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... |