#include<bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 2;
vector<int>g[nax];
int n, m;
bool vis[nax];
int cr, sm;
void dfs(int v) {
vis[v] = true;
sm += g[v].size();
++cr;
for(int u : g[v]) if(!vis[u]) {
dfs(u);
}
}
long long C(int n, int r) {
long long ret = 1;
for(int i=n-r+1; i<=n; ++i) {
ret *= i;
}
for(int i=1; i<=r; ++i) {
ret /= i;
}
return ret;
}
void PlayGround() {
cin>>n>>m;
for(int i=0; i<m; ++i) {
int u, v;
cin>>u>>v;
g[u].push_back(v);
g[v].push_back(u);
}
long long ans = 0;
for(int i=1; i<=n; ++i) if(!vis[i]) {
cr = sm = 0;
dfs(i);
if(sm==cr * 2) {
if(cr>=3) ans += C(cr, 3) * 6;
} else {
long long cur = 0;
for(int i=1; i<=cr-2; ++i) {
cur += C(cr-i, 2);
}
cur *= 2;
ans += cur;
}
}
cout<<ans<<'\n';
// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
8928 KB |
Output is correct |
2 |
Correct |
61 ms |
10228 KB |
Output is correct |
3 |
Correct |
65 ms |
8616 KB |
Output is correct |
4 |
Correct |
38 ms |
9408 KB |
Output is correct |
5 |
Correct |
55 ms |
8060 KB |
Output is correct |
6 |
Correct |
51 ms |
8164 KB |
Output is correct |
7 |
Correct |
62 ms |
7752 KB |
Output is correct |
8 |
Correct |
45 ms |
7972 KB |
Output is correct |
9 |
Correct |
38 ms |
7356 KB |
Output is correct |
10 |
Correct |
43 ms |
7632 KB |
Output is correct |
11 |
Correct |
30 ms |
6896 KB |
Output is correct |
12 |
Correct |
37 ms |
6704 KB |
Output is correct |
13 |
Correct |
33 ms |
6612 KB |
Output is correct |
14 |
Correct |
32 ms |
6500 KB |
Output is correct |
15 |
Correct |
27 ms |
6028 KB |
Output is correct |
16 |
Correct |
24 ms |
5844 KB |
Output is correct |
17 |
Correct |
2 ms |
2680 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
2 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2684 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
5960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
5944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |