#include <iostream>
using namespace std;
long long int son[1000005],ans,cnt,tmp[1000005],n,m,road[1000005],map[1000005][2];
void dfs(int x,int fa)
{
son[x]=1;
long long int g=road[x];
while(g!=-1)
{
long long int now=map[g][0];
if(now!=fa)
{
dfs(now,x);
son[x]+=son[now];
}
g=map[g][1];
}
return ;
}
void find(int x,int fa)
{
cnt=0;
long long int g=road[x];
while(g!=-1)
{
long long int now=map[g][0];
if(now!=fa)
{
ans+=(n-son[now]-1)*son[now];
}
g=map[g][1];
}
ans+=(n-son[x])*(son[x]-1);
g=road[x];
while(g!=-1)
{
long long int now=map[g][0];
if(now!=fa)
{
find(now,x);
}
g=map[g][1];
}
return ;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)road[i]=-1;
for(int i=1;i<=m;i++)
{
int u,v;
cin>>u>>v;
map[i*2][0]=v;
map[i*2][1]=road[u];
road[u]=i*2;
map[i*2+1][0]=u;
map[i*2+1][1]=road[v];
road[v]=i*2+1;
}
dfs(1,-1);
find(1,-1);
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
651 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
651 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1114 ms |
357652 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
130 ms |
6264 KB |
Output is correct |
2 |
Correct |
135 ms |
6316 KB |
Output is correct |
3 |
Correct |
135 ms |
6264 KB |
Output is correct |
4 |
Correct |
133 ms |
6264 KB |
Output is correct |
5 |
Correct |
146 ms |
6264 KB |
Output is correct |
6 |
Correct |
147 ms |
8852 KB |
Output is correct |
7 |
Correct |
135 ms |
7932 KB |
Output is correct |
8 |
Correct |
157 ms |
7672 KB |
Output is correct |
9 |
Correct |
134 ms |
7160 KB |
Output is correct |
10 |
Incorrect |
126 ms |
6280 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Runtime error |
659 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
6264 KB |
Output is correct |
2 |
Correct |
144 ms |
6232 KB |
Output is correct |
3 |
Runtime error |
910 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
651 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
651 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |