#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+100;
vector<int> g[N];
int dep[N];
int a[N];
int n,ans;
void dfs2(int u,int p)
{
for(auto x:g[u]){
if(x==p)continue;
dep[x]=dep[u]+1;
dfs2(x,u);
a[u]+=a[x];
}
}
void dfs(int u,int p,int ann)
{
ans+=ann-(n);
//cout<<u<<" "<<ann<<endl;
ans+=1;
for(auto x:g[u]){
if(x==p)continue;
dfs(x,u,ann+(n-a[x])-a[x]);
}
}
void solve()
{
int m,ann=0;
cin>>n>>m;
for(int i=1;i<=n;i++)a[i]=1;
while(m--){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
dfs2(1,1);
for(int i=1;i<=n;i++){
ann+=dep[i];
}
dfs(1,1,ann);
cout<<ans<<endl;
}
main()
{
int t=1;
// cin>>t;
while(t--)solve();
}
Compilation message
count_triplets.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
51 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
492 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
492 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1118 ms |
560432 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
3 ms |
2764 KB |
Output is correct |
5 |
Correct |
3 ms |
2636 KB |
Output is correct |
6 |
Correct |
3 ms |
2664 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2636 KB |
Output is correct |
9 |
Correct |
3 ms |
2636 KB |
Output is correct |
10 |
Incorrect |
3 ms |
2636 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
9056 KB |
Output is correct |
2 |
Correct |
103 ms |
9116 KB |
Output is correct |
3 |
Correct |
127 ms |
9284 KB |
Output is correct |
4 |
Correct |
115 ms |
9216 KB |
Output is correct |
5 |
Correct |
107 ms |
9188 KB |
Output is correct |
6 |
Correct |
117 ms |
12832 KB |
Output is correct |
7 |
Correct |
133 ms |
11844 KB |
Output is correct |
8 |
Correct |
124 ms |
11100 KB |
Output is correct |
9 |
Correct |
115 ms |
10432 KB |
Output is correct |
10 |
Incorrect |
98 ms |
9164 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2660 KB |
Output is correct |
2 |
Correct |
3 ms |
2636 KB |
Output is correct |
3 |
Runtime error |
629 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
9124 KB |
Output is correct |
2 |
Correct |
114 ms |
9096 KB |
Output is correct |
3 |
Runtime error |
802 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
492 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
492 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |