// https://oj.uz/problem/view/APIO18_duathlon > p520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5;
vector<int> adj[MAXN];
bool vis[MAXN];
pair<int, bool> dfs(int v, int pai) {
vis[v] = true;
int sz = 1;
bool cycle = false;
for (int viz : adj[v]) {
if (vis[viz]) {
if (viz != pai) cycle = true;
continue;
}
pair<int, int> res = dfs(viz, v);
sz += res.first;
if (res.second) cycle = true;
}
return {sz, cycle};
}
ll qty(pair<int, bool> res) {
int n = res.first; bool cycle = res.second;
return (ll)(n) * (ll)(n - 1) * (ll)(n - 2) / (ll)(3 - 2*cycle);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, m; cin >> n >> m;
for (int i=0; i<m; i++) {
int u, v; cin >> u >> v;
u--; v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
ll ans = 0;
for (int i=0; i<n; i++) {
if (vis[i]) continue;
// assert(i==0);
ans += qty(dfs(i, -1));
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2824 KB |
Output is correct |
4 |
Correct |
3 ms |
2808 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2824 KB |
Output is correct |
4 |
Correct |
3 ms |
2808 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
13664 KB |
Output is correct |
2 |
Correct |
37 ms |
14236 KB |
Output is correct |
3 |
Correct |
34 ms |
11156 KB |
Output is correct |
4 |
Correct |
44 ms |
13128 KB |
Output is correct |
5 |
Correct |
45 ms |
9800 KB |
Output is correct |
6 |
Correct |
34 ms |
9752 KB |
Output is correct |
7 |
Correct |
34 ms |
8700 KB |
Output is correct |
8 |
Correct |
31 ms |
9288 KB |
Output is correct |
9 |
Correct |
30 ms |
8016 KB |
Output is correct |
10 |
Correct |
31 ms |
8784 KB |
Output is correct |
11 |
Correct |
26 ms |
6840 KB |
Output is correct |
12 |
Correct |
30 ms |
6728 KB |
Output is correct |
13 |
Correct |
24 ms |
6660 KB |
Output is correct |
14 |
Correct |
22 ms |
6652 KB |
Output is correct |
15 |
Correct |
17 ms |
5960 KB |
Output is correct |
16 |
Correct |
20 ms |
5968 KB |
Output is correct |
17 |
Correct |
3 ms |
2896 KB |
Output is correct |
18 |
Correct |
3 ms |
2820 KB |
Output is correct |
19 |
Correct |
3 ms |
2896 KB |
Output is correct |
20 |
Correct |
3 ms |
2896 KB |
Output is correct |
21 |
Correct |
3 ms |
2676 KB |
Output is correct |
22 |
Correct |
3 ms |
2896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
5968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
5968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2824 KB |
Output is correct |
4 |
Correct |
3 ms |
2808 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2640 KB |
Output is correct |
2 |
Correct |
3 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2824 KB |
Output is correct |
4 |
Correct |
3 ms |
2808 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Incorrect |
2 ms |
2640 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |