#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; assert(m <= n - 1);
for (int i = 1; i <= m; 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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
15704 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
15704 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
15708 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
2 ms |
10072 KB |
Output is correct |
4 |
Correct |
3 ms |
10076 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 |
3 ms |
10076 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
13684 KB |
Output is correct |
2 |
Correct |
62 ms |
13652 KB |
Output is correct |
3 |
Correct |
57 ms |
13652 KB |
Output is correct |
4 |
Correct |
62 ms |
13632 KB |
Output is correct |
5 |
Correct |
64 ms |
13904 KB |
Output is correct |
6 |
Correct |
58 ms |
16468 KB |
Output is correct |
7 |
Correct |
70 ms |
15792 KB |
Output is correct |
8 |
Correct |
61 ms |
15444 KB |
Output is correct |
9 |
Correct |
59 ms |
14844 KB |
Output is correct |
10 |
Incorrect |
64 ms |
13652 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10076 KB |
Output is correct |
2 |
Correct |
3 ms |
10076 KB |
Output is correct |
3 |
Runtime error |
8 ms |
15708 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
13648 KB |
Output is correct |
2 |
Correct |
60 ms |
13532 KB |
Output is correct |
3 |
Runtime error |
7 ms |
15708 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
15704 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
15704 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |