#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector <int> adj[300001];
int sze[300001];
bool vis[300001];
void calc (int pos, int par) {
vis[pos] = 1;
for (auto j : adj[pos]) {
if (j == par) continue;
calc(j, pos);
sze[pos] += sze[j];
}
sze[pos]++;
}
int ans = 0;
void dfs (int pos, int par) {
vis[pos] = 1;
ans += 2 * (n - sze[pos]) * (sze[pos] - 1);
int cur = 0;
for (auto j : adj[pos]) {
if (j == par) continue;
ans += 2 * sze[j] * cur;
cur += sze[j];
dfs(j, pos);
}
}
signed main () {
cin >> n; int m; cin >> m;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) if (!vis[i]) calc(i, -1);
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i, -1);
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
787 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
787 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
17508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
10076 KB |
Output is correct |
2 |
Correct |
3 ms |
10072 KB |
Output is correct |
3 |
Correct |
3 ms |
10076 KB |
Output is correct |
4 |
Correct |
3 ms |
10072 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10076 KB |
Output is correct |
7 |
Correct |
3 ms |
10076 KB |
Output is correct |
8 |
Correct |
3 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10072 KB |
Output is correct |
10 |
Incorrect |
4 ms |
10076 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
13660 KB |
Output is correct |
2 |
Correct |
55 ms |
13904 KB |
Output is correct |
3 |
Correct |
56 ms |
13736 KB |
Output is correct |
4 |
Correct |
58 ms |
13660 KB |
Output is correct |
5 |
Correct |
68 ms |
13620 KB |
Output is correct |
6 |
Correct |
66 ms |
16464 KB |
Output is correct |
7 |
Correct |
82 ms |
16100 KB |
Output is correct |
8 |
Correct |
59 ms |
15356 KB |
Output is correct |
9 |
Correct |
66 ms |
14672 KB |
Output is correct |
10 |
Incorrect |
67 ms |
13676 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
10072 KB |
Output is correct |
2 |
Correct |
3 ms |
10076 KB |
Output is correct |
3 |
Runtime error |
577 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
13812 KB |
Output is correct |
2 |
Correct |
66 ms |
13652 KB |
Output is correct |
3 |
Runtime error |
950 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
787 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
787 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |