#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ar = array<int,2>;
const int mxN = (int)1e5+10;
int n, m, ans, vis[mxN];
vector<int> v, adj[mxN];
void dfs(int s){
vis[s]=1; v.pb(s);
for(auto u : adj[s])
if(!vis[u]) dfs(u);
}
int32_t main() {
cin >> n >> m;
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
adj[a].pb(b), adj[b].pb(a);
}
for(int i = 1; i <= n; i++){
if(vis[i]) continue;
v.clear(); dfs(i);
bool ok = 1; int x = sz(v);
for(auto u : v) ok&=sz(adj[u])==2;
if(ok) ans+=x*(x-1)*(x-2);
else ans+= (x*(x-1)*(x-2))/3;
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
12052 KB |
Output is correct |
2 |
Correct |
85 ms |
12124 KB |
Output is correct |
3 |
Correct |
56 ms |
9320 KB |
Output is correct |
4 |
Correct |
76 ms |
10776 KB |
Output is correct |
5 |
Correct |
81 ms |
8776 KB |
Output is correct |
6 |
Correct |
79 ms |
8652 KB |
Output is correct |
7 |
Correct |
58 ms |
7696 KB |
Output is correct |
8 |
Correct |
55 ms |
8236 KB |
Output is correct |
9 |
Correct |
86 ms |
7116 KB |
Output is correct |
10 |
Correct |
60 ms |
7636 KB |
Output is correct |
11 |
Correct |
49 ms |
6428 KB |
Output is correct |
12 |
Correct |
63 ms |
6532 KB |
Output is correct |
13 |
Correct |
45 ms |
6368 KB |
Output is correct |
14 |
Correct |
44 ms |
6220 KB |
Output is correct |
15 |
Correct |
37 ms |
5868 KB |
Output is correct |
16 |
Correct |
35 ms |
5772 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3408 KB |
Output is correct |
19 |
Correct |
3 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
8264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
57 ms |
8272 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |