#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long ans;
vector<int> adj[N];
int subtree[N], n;
void dfs(int v, int p = 0) {
subtree[v] = 1;
for (int u : adj[v]) if (u != p) {
dfs(u, v);
subtree[v] += subtree[u];
}
long long aux = (v == 1 ? 0ll : 1ll * (n - subtree[v]));
vector<long long> pref;
pref.push_back(aux);
long long local_ans = 0;
for (int u : adj[v]) if (u != p) {
local_ans += pref.back() * subtree[u];
pref.push_back(pref.back() + subtree[u]);
}
ans += 2ll * local_ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m; cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
593 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
593 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1131 ms |
660204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
2 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
2 ms |
2796 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
3 ms |
2796 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2668 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
6252 KB |
Output is correct |
2 |
Correct |
64 ms |
7660 KB |
Output is correct |
3 |
Correct |
61 ms |
7532 KB |
Output is correct |
4 |
Correct |
68 ms |
7532 KB |
Output is correct |
5 |
Correct |
63 ms |
7532 KB |
Output is correct |
6 |
Correct |
89 ms |
15084 KB |
Output is correct |
7 |
Correct |
78 ms |
12524 KB |
Output is correct |
8 |
Correct |
74 ms |
11244 KB |
Output is correct |
9 |
Correct |
72 ms |
10056 KB |
Output is correct |
10 |
Incorrect |
55 ms |
7532 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Runtime error |
982 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
6252 KB |
Output is correct |
2 |
Correct |
65 ms |
7532 KB |
Output is correct |
3 |
Execution timed out |
1146 ms |
863468 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
593 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
593 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |