#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5, M = 2e5;
vector<int> adj[N];
bool explored[N];
int n, m, dp[N][3], ans;
void dfs(int v, int p = -1) {
//cerr << v << endl;
explored[v] = true;
int s1 = 0, s2 = 0;
dp[v][0] = 1;
for (int i : adj[v]) {
if (i != p){
dfs(i, v);
dp[v][0] += dp[i][0];
dp[v][1] += dp[i][0] + dp[i][1];
dp[v][2] += dp[i][1] * 2;
s2 += dp[i][1];
s1 += dp[i][0];
}
}
for (int i : adj[v]) {
if (i != p) {
s2 -= dp[i][1];
s1 -= dp[i][0];
dp[v][2] += s2 * dp[i][0] * 2;
dp[v][2] += s1 * dp[i][0];
s2 += dp[i][1];
s1 += dp[i][0];
}
}
ans += dp[v][2];
}
int solveTestCase() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i < n; i++) {
if (!explored[i])
dfs(i);
//cerr << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
}
cout << ans;
return 0;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin >> t;
while (t--)
solveTestCase();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
592 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
592 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1114 ms |
449144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2816 KB |
Output is correct |
2 |
Correct |
2 ms |
2816 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
2 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
2 ms |
2816 KB |
Output is correct |
10 |
Correct |
2 ms |
2816 KB |
Output is correct |
11 |
Correct |
2 ms |
2816 KB |
Output is correct |
12 |
Correct |
3 ms |
2816 KB |
Output is correct |
13 |
Correct |
2 ms |
2816 KB |
Output is correct |
14 |
Correct |
3 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2816 KB |
Output is correct |
18 |
Correct |
2 ms |
2816 KB |
Output is correct |
19 |
Correct |
2 ms |
2816 KB |
Output is correct |
20 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
8804 KB |
Output is correct |
2 |
Correct |
57 ms |
10104 KB |
Output is correct |
3 |
Correct |
58 ms |
10104 KB |
Output is correct |
4 |
Correct |
61 ms |
10040 KB |
Output is correct |
5 |
Correct |
59 ms |
10104 KB |
Output is correct |
6 |
Correct |
73 ms |
14584 KB |
Output is correct |
7 |
Correct |
67 ms |
13432 KB |
Output is correct |
8 |
Correct |
65 ms |
12536 KB |
Output is correct |
9 |
Correct |
76 ms |
11768 KB |
Output is correct |
10 |
Correct |
57 ms |
10144 KB |
Output is correct |
11 |
Correct |
56 ms |
10104 KB |
Output is correct |
12 |
Correct |
64 ms |
10104 KB |
Output is correct |
13 |
Correct |
58 ms |
10104 KB |
Output is correct |
14 |
Correct |
63 ms |
9720 KB |
Output is correct |
15 |
Correct |
53 ms |
9464 KB |
Output is correct |
16 |
Correct |
33 ms |
8184 KB |
Output is correct |
17 |
Correct |
53 ms |
10484 KB |
Output is correct |
18 |
Correct |
48 ms |
10340 KB |
Output is correct |
19 |
Correct |
41 ms |
10336 KB |
Output is correct |
20 |
Correct |
40 ms |
10344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2816 KB |
Output is correct |
3 |
Runtime error |
748 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
8952 KB |
Output is correct |
2 |
Correct |
63 ms |
10052 KB |
Output is correct |
3 |
Runtime error |
901 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
592 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
592 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |