#include <bits/stdc++.h>
#define N 100050
using namespace std;
typedef long long ll;
ll n, m, c, ans, ok[N];
vector<ll> grafo[N];
ll ini, mid, fim, sz[N], tot = 0;
int ultimo;
void dfs(int x)
{
ultimo = x;
tot ++;
ok[x] = 1;
for(auto v: grafo[x])
{
if(ok[v]) continue;
dfs(v);
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
for(ll i = 1, a, b; i <= m; i++)
{
cin>>a>>b;
grafo[a].push_back(b);
grafo[b].push_back(a);
}
for(int i = 1; i <= n; i++)
{
if(ok[i]) continue;
tot = 0;
ultimo = i;
dfs(i);
int ciclo = 0;
for(auto v: grafo[ultimo])
{
if(v == i) ciclo = 1;
}
if(tot > 2 and ciclo) ans += (tot * (tot - 1) * (tot - 2));
else if(tot > 2 and !ciclo) ans += (tot * (tot - 1) * (tot - 2))/3;
}
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
9820 KB |
Output is correct |
2 |
Correct |
100 ms |
11064 KB |
Output is correct |
3 |
Correct |
157 ms |
11064 KB |
Output is correct |
4 |
Correct |
102 ms |
13068 KB |
Output is correct |
5 |
Correct |
118 ms |
13068 KB |
Output is correct |
6 |
Correct |
115 ms |
14296 KB |
Output is correct |
7 |
Correct |
126 ms |
15160 KB |
Output is correct |
8 |
Correct |
135 ms |
16612 KB |
Output is correct |
9 |
Correct |
157 ms |
17356 KB |
Output is correct |
10 |
Correct |
94 ms |
18784 KB |
Output is correct |
11 |
Incorrect |
74 ms |
19340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
19340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
19836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
19836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
19980 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |