#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<int> 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;
int 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 |
659 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1136 ms |
688308 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 |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
388 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
324 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 |
52 ms |
6816 KB |
Output is correct |
2 |
Correct |
52 ms |
7416 KB |
Output is correct |
3 |
Correct |
57 ms |
7492 KB |
Output is correct |
4 |
Correct |
54 ms |
7500 KB |
Output is correct |
5 |
Correct |
70 ms |
7444 KB |
Output is correct |
6 |
Correct |
63 ms |
13388 KB |
Output is correct |
7 |
Correct |
60 ms |
11332 KB |
Output is correct |
8 |
Correct |
67 ms |
10340 KB |
Output is correct |
9 |
Correct |
60 ms |
9476 KB |
Output is correct |
10 |
Incorrect |
47 ms |
7492 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 |
788 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
6832 KB |
Output is correct |
2 |
Correct |
60 ms |
7452 KB |
Output is correct |
3 |
Runtime error |
921 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
659 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |