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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
vector<vector<int>> graph;
vector<bool> bl;
ll cnt = 0;
void dfs(int nd, int ss){
cnt++;
bl[nd] = 1;
for(int x: graph[nd]) if(x != ss) dfs(x, nd);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
graph.resize(n);
bl.resize(n, 0);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b; a--, b--;
graph[a].pb(b);
graph[b].pb(a);
}
ll ans = 0;
for(int i = 0; i < n; i++) if(!bl[i]){
cnt = 0;
dfs(i, -1);
ans+=(cnt*(cnt-1)*(cnt-2))/3;
}
cout << ans << "\n";
}
# | 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... |