#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
--u; --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<long long> sbt(n, 0);
long long ans = 0;
function<void(int, int)> dfs0 = [&](int u, int p) {
sbt[u] = 1;
for (int v : g[u]) {
if (v != p) {
dfs0(v, u);
sbt[u] += sbt[v];
}
}
long long sum = n - 1;
long long sbtp = n - sbt[u];
ans += sbtp * 1LL * (sum - sbtp);
for (int v : g[u]) {
if (v != p) {
ans += sbt[v] * 1LL * (sum - sbt[v]);
}
}
};
dfs0(0, -1);
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
573 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
573 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1130 ms |
667204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
6596 KB |
Output is correct |
2 |
Correct |
52 ms |
6612 KB |
Output is correct |
3 |
Correct |
51 ms |
6620 KB |
Output is correct |
4 |
Correct |
50 ms |
6568 KB |
Output is correct |
5 |
Correct |
52 ms |
6596 KB |
Output is correct |
6 |
Correct |
61 ms |
12484 KB |
Output is correct |
7 |
Correct |
63 ms |
10416 KB |
Output is correct |
8 |
Correct |
57 ms |
9540 KB |
Output is correct |
9 |
Correct |
54 ms |
8556 KB |
Output is correct |
10 |
Incorrect |
45 ms |
6652 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Runtime error |
740 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
6636 KB |
Output is correct |
2 |
Correct |
51 ms |
6576 KB |
Output is correct |
3 |
Runtime error |
929 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
573 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
573 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |