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>
using namespace std;
#define int long long
vector<int> adj[200001];
bool visited[200001];
int DP[200001][4];
bool isCycle;
int tot;
void dfs(int x,int p){
if(visited[x]){
isCycle=true;
return;
}
tot++;
visited[x]=true;
for(int&i:adj[x])if(i!=p)dfs(i,x);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
for(auto&i:DP)i[0]=1;
for(int i=1;i<=200000;i++)for(int j=1;j<=3;j++)DP[i][j]=DP[i-1][j]+DP[i-1][j-1];
int n,m;
cin >> n >> m;
for(int i=1;i<=m;i++){
int a,b;cin>>a>>b;
adj[a].emplace_back(b);
adj[b].emplace_back(a);
}
int ans = 0;
for(int i=1;i<=n;i++)if(!visited[i]){
isCycle = false;
tot = 0;
dfs(i,0);
if(isCycle)ans+=tot*(tot-1)*(tot-2);
else ans+=DP[tot][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... |