#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxn = 1e5+10;
vector<int> tree[mxn];
int N,M;
bitset<mxn> vis;
int dp[mxn];
ll ans = 0;
void dfs1(int now,int fa){
vis[now] = true;
dp[now] = 1;
for(auto nxt:tree[now]){
if(nxt == fa)continue;
dfs1(nxt,now);
dp[now] += dp[nxt];
}
return;
}
void dfs2(int now,int fa,int sz){
ll sum = 0;
for(auto nxt:tree[now]){
if(nxt == fa)continue;
dfs2(nxt,now,sz);
ans += sum*dp[nxt]*2;
sum += dp[nxt];
}
ll ts = sz-dp[now];
ans += sum*ts*2;
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M;
for(int i = 0;i<M;i++){
int a,b;
cin>>a>>b;
tree[a].push_back(b);
tree[b].push_back(a);
}
for(int i = 1;i<=N;i++){
if(vis[i])continue;
dfs1(i,i);
dfs2(i,i,dp[i]);
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
472 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
472 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1076 ms |
1007892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
2 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
2848 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
2 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2904 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2868 KB |
Output is correct |
19 |
Correct |
2 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
7596 KB |
Output is correct |
2 |
Correct |
27 ms |
7516 KB |
Output is correct |
3 |
Correct |
26 ms |
7616 KB |
Output is correct |
4 |
Correct |
27 ms |
7692 KB |
Output is correct |
5 |
Correct |
30 ms |
7504 KB |
Output is correct |
6 |
Correct |
35 ms |
12564 KB |
Output is correct |
7 |
Correct |
30 ms |
10836 KB |
Output is correct |
8 |
Correct |
34 ms |
10072 KB |
Output is correct |
9 |
Correct |
32 ms |
9040 KB |
Output is correct |
10 |
Correct |
29 ms |
7620 KB |
Output is correct |
11 |
Correct |
27 ms |
7516 KB |
Output is correct |
12 |
Correct |
26 ms |
7512 KB |
Output is correct |
13 |
Correct |
39 ms |
7508 KB |
Output is correct |
14 |
Correct |
24 ms |
7248 KB |
Output is correct |
15 |
Correct |
20 ms |
7004 KB |
Output is correct |
16 |
Correct |
21 ms |
5972 KB |
Output is correct |
17 |
Correct |
18 ms |
7888 KB |
Output is correct |
18 |
Correct |
31 ms |
7812 KB |
Output is correct |
19 |
Correct |
17 ms |
7884 KB |
Output is correct |
20 |
Correct |
19 ms |
7768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2820 KB |
Output is correct |
3 |
Runtime error |
556 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
7504 KB |
Output is correct |
2 |
Correct |
29 ms |
7516 KB |
Output is correct |
3 |
Runtime error |
638 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
472 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
472 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |