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 endl '\n'
using namespace std;
long long n, m, brv=0, bv=0;
bool used[300005];
vector<int> gr[300005];
bool dfs(int v)
{
used[v]=1;
brv++;
int brs=gr[v].size();
for(int i=0; i<brs; i++)
{
if(brv>2 && gr[v][i]==bv) return 1;
if(used[gr[v][i]]) continue;
return dfs(gr[v][i]);
}
return 0;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=0; i<m; i++)
{
int v, u;
cin>>v>>u;
gr[v].push_back(u);
gr[u].push_back(v);
}
long long ans=0;
for(int i=1; i<=n; i++)
{
if(used[i]) continue;
brv=0;
bv=i;
if(dfs(i)) ans+=brv*(brv-1)*(brv-2);
else ans+=brv*(brv-1)*(brv-2)/3;
}
cout<<ans<<endl;
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... |