#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> pii;
#define f first
#define s second
const int maxn = 1e5+10;
vector<int> grafo[maxn];
int n, m, dp[maxn], sz[maxn], qtd[maxn], qtd2[maxn];
int solve(int u, int p = 0){ // lca of path is u, 1 as a root
int ans = 0; // sum of dps
sz[u] = 1;
for(int v : grafo[u]){
if(v == p) continue;
ans += solve(v, u);
sz[u] += sz[v];
qtd2[u] += (qtd2[v] + sz[v]) * qtd[u];
}
int qtdd = sz[u] - 1;
for(int v : grafo[u]){
if(v == p) continue;
qtdd -= sz[v];
dp[u] += sz[v] * qtdd * qtd[u];
dp[u] += (sz[u] - sz[v]) * qtd2[v];
}
return ans + dp[u];
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin >> n >> m;
for(int i=1; i<=m; i++){
int u, v;
cin >> u >> v;
grafo[u].push_back(v);
grafo[v].push_back(u);
}
int ans = 0;
for(int i=1; i<=n; i++) qtd[i] = 1;
for(int i=1; i<=n; i++){
if(!sz[i]) ans += solve(i);
}
cout << 2*ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1116 ms |
413804 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2796 KB |
Output is correct |
3 |
Correct |
2 ms |
2796 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
2 ms |
2796 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
2 ms |
2796 KB |
Output is correct |
10 |
Correct |
2 ms |
2796 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
3 ms |
2796 KB |
Output is correct |
13 |
Correct |
2 ms |
2796 KB |
Output is correct |
14 |
Correct |
3 ms |
2796 KB |
Output is correct |
15 |
Correct |
2 ms |
2796 KB |
Output is correct |
16 |
Correct |
2 ms |
2796 KB |
Output is correct |
17 |
Correct |
3 ms |
2796 KB |
Output is correct |
18 |
Correct |
2 ms |
2796 KB |
Output is correct |
19 |
Correct |
2 ms |
2796 KB |
Output is correct |
20 |
Correct |
2 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
9708 KB |
Output is correct |
2 |
Correct |
63 ms |
9580 KB |
Output is correct |
3 |
Correct |
63 ms |
9580 KB |
Output is correct |
4 |
Correct |
72 ms |
9580 KB |
Output is correct |
5 |
Correct |
71 ms |
9708 KB |
Output is correct |
6 |
Correct |
76 ms |
13292 KB |
Output is correct |
7 |
Correct |
88 ms |
12268 KB |
Output is correct |
8 |
Correct |
80 ms |
11696 KB |
Output is correct |
9 |
Correct |
74 ms |
10860 KB |
Output is correct |
10 |
Correct |
63 ms |
9580 KB |
Output is correct |
11 |
Correct |
67 ms |
9708 KB |
Output is correct |
12 |
Correct |
65 ms |
9708 KB |
Output is correct |
13 |
Correct |
71 ms |
9708 KB |
Output is correct |
14 |
Correct |
66 ms |
9452 KB |
Output is correct |
15 |
Correct |
76 ms |
9196 KB |
Output is correct |
16 |
Correct |
34 ms |
8300 KB |
Output is correct |
17 |
Correct |
48 ms |
8288 KB |
Output is correct |
18 |
Correct |
42 ms |
8412 KB |
Output is correct |
19 |
Correct |
43 ms |
8540 KB |
Output is correct |
20 |
Correct |
42 ms |
8412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2796 KB |
Output is correct |
2 |
Correct |
2 ms |
2796 KB |
Output is correct |
3 |
Runtime error |
742 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
9600 KB |
Output is correct |
2 |
Correct |
76 ms |
9452 KB |
Output is correct |
3 |
Runtime error |
911 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
626 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |