#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 |
1 |
Incorrect |
2 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
10588 KB |
Output is correct |
2 |
Correct |
24 ms |
10588 KB |
Output is correct |
3 |
Incorrect |
24 ms |
10504 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
24 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
10588 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
7260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |