#include <iostream>
using namespace std;
long long int cnt,tag[100005],son[1000005],ans,tmp[1000005],n,m,road[1000005],map[1000005][2];
void dfs(int x,int fa)
{
tag[x]=1;
son[x]=1;
cnt++;
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+=(cnt-son[now]-1)*son[now];
}
g=map[g][1];
}
ans+=(cnt-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;
}
for(int i=1;i<=n;i++)
{
if(tag[i]==0)
{
cnt=0;
dfs(i,-1);
find(i,-1);
//cout<<i<<" "<<ans<<endl;
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
689 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
689 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1122 ms |
371708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
5948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
135 ms |
5784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
689 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
689 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |