#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ar = array<int,2>;
const int mxN = (int)1e5+10;
int n, m, VV[mxN];
vector<int> adj[mxN];
int sub[mxN], totsq[mxN],xd=0;
void dfs(int s, int p){
VV[s]=1; sub[s]=1; totsq[s]=0;
for(auto u : adj[s]){
if(u==p) continue;
dfs(u,s); sub[s]+=sub[u];
totsq[s]+=sub[u]*sub[u];
}
}
void reroot(int s, int u, bool chk=1){
totsq[s]-=sub[u]*sub[u];
totsq[u]+=(n-sub[u])*(n-sub[u]);
sub[s]-=sub[u]; sub[u]+=sub[s];
if(chk) xd+=totsq[u];
}
void dfs2(int s, int p){
for(auto u : adj[s]){
if(u==p) continue;
reroot(s,u);
dfs2(u,s);
reroot(u,s,0);
}
}
int solve(int s){
dfs(s,-1); xd = totsq[s];
int tot = sub[s]; dfs2(s,-1);
return tot*(tot-1)*(tot-1)-xd;
}
int32_t main() {
cin >> n >> m; int ans = 0;
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b;
adj[a].pb(b), adj[b].pb(a);
}
for(int i = 1; i <= n; i++)
if(!VV[i]) ans+=solve(i);
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
431 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
431 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1096 ms |
880672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2772 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
3 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
9892 KB |
Output is correct |
2 |
Correct |
58 ms |
9952 KB |
Output is correct |
3 |
Correct |
60 ms |
9932 KB |
Output is correct |
4 |
Correct |
57 ms |
9936 KB |
Output is correct |
5 |
Correct |
69 ms |
10036 KB |
Output is correct |
6 |
Correct |
65 ms |
13548 KB |
Output is correct |
7 |
Correct |
67 ms |
12616 KB |
Output is correct |
8 |
Correct |
67 ms |
11968 KB |
Output is correct |
9 |
Correct |
86 ms |
11252 KB |
Output is correct |
10 |
Incorrect |
78 ms |
9956 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Runtime error |
478 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
9920 KB |
Output is correct |
2 |
Correct |
98 ms |
9752 KB |
Output is correct |
3 |
Runtime error |
535 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
431 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
431 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |