#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int M = 3e5+5, MOD = 1e9+7;
int d[M], noc[M], n, dp[M], vis[M];
vector<int> node[M];
void dfs(int s, int p = 1) {
noc[s]++;
vis[s] = true;
for (int i:node[s]) {
if (!vis[i]) {
d[i] = d[s]+1;
dfs(i, s);
noc[s] += noc[i];
}
}
}
void dfs2(int s, int p = 1) {
vis[s] = true;
for (int i:node[s]) {
if (!vis[i]) {
dp[i] = dp[s] + n - 2*noc[i];
dfs2(i, s);
}
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
node[a].push_back(b);
node[b].push_back(a);
} dfs(1);
for (int i = 1; i <= n; i++) dp[1] += d[i], vis[i] = 0;
dfs2(1);
int ans = 0;
for (int i = 1; i <= n; i++) ans += dp[i] - n + 1;
cout << ans << endl;
return 0;
}
/*
4 3
1 2 2 3 3 4
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
81 ms |
19812 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7468 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Incorrect |
4 ms |
7420 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
14204 KB |
Output is correct |
2 |
Correct |
53 ms |
14248 KB |
Output is correct |
3 |
Correct |
57 ms |
14240 KB |
Output is correct |
4 |
Correct |
60 ms |
14184 KB |
Output is correct |
5 |
Correct |
59 ms |
14180 KB |
Output is correct |
6 |
Correct |
85 ms |
17036 KB |
Output is correct |
7 |
Correct |
64 ms |
16444 KB |
Output is correct |
8 |
Correct |
61 ms |
15808 KB |
Output is correct |
9 |
Correct |
56 ms |
15208 KB |
Output is correct |
10 |
Incorrect |
45 ms |
14196 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Incorrect |
5 ms |
7380 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
14220 KB |
Output is correct |
2 |
Correct |
54 ms |
14036 KB |
Output is correct |
3 |
Incorrect |
63 ms |
16008 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |