#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
using namespace std;
constexpr static int MXN = 1e5;
int n, m;
vector<int> g[MXN];
int subtree_size[MXN];
int res;
void dfs(int node, int p)
{
subtree_size[node] = 1;
for (int c : g[node])
{
if (c == p)
continue;
dfs(c, node);
subtree_size[node] += subtree_size[c];
res += subtree_size[c] * (n - subtree_size[c] - 1);
}
int rem = n - subtree_size[node];
res += (subtree_size[node] - 1) * rem;
}
int32_t main()
{
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--,b--;
g[a].pb(b);
g[b].pb(a);
}
dfs(0, 0);
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
400 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
400 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1090 ms |
874460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
3 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2664 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2660 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
7452 KB |
Output is correct |
2 |
Correct |
57 ms |
8360 KB |
Output is correct |
3 |
Correct |
83 ms |
8364 KB |
Output is correct |
4 |
Correct |
54 ms |
8400 KB |
Output is correct |
5 |
Correct |
56 ms |
8364 KB |
Output is correct |
6 |
Correct |
57 ms |
11172 KB |
Output is correct |
7 |
Correct |
71 ms |
10596 KB |
Output is correct |
8 |
Correct |
66 ms |
9932 KB |
Output is correct |
9 |
Correct |
82 ms |
9376 KB |
Output is correct |
10 |
Incorrect |
78 ms |
8284 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Runtime error |
458 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
7532 KB |
Output is correct |
2 |
Correct |
60 ms |
7596 KB |
Output is correct |
3 |
Runtime error |
629 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
400 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
400 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |