#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
bool sub3=true;
ll N,M;
ll x,y;
ll A,B,ans;
bool V[300005];
vector<ll> grafo[300005];
ll S[300005];
map <pll,ll> E;
void DFSsub3(int k){
B++;
if(V[k])
return;
A++;
V[k]=true;
for(int f:grafo[k])
DFSsub3(f);}
void DFS(int k, int p=-1){
for(int f:grafo[k])
if(f!=p)
DFS(f,k);
E[{p,k}]=1;
for(int f:grafo[k])
if(f!=p)
E[{p,k}]+=E[{k,f}];
E[{k,p}]=N-E[{p,k}];
}
int main(){
cin>>N>>M;
for(int i=0;i<M;i++){
cin>>x>>y;
grafo[x].push_back(y);
grafo[y].push_back(x);
}
for(int i=1;i<N+1;i++)
if(grafo[i].size()>2)
sub3=false;
sub3=false;
if(sub3){
for(int i=1;i<N+1;i++)
if(!V[i]){
A=B=0;
DFSsub3(i);
if(B-1==2*A)
ans+=(A*(A-1)*(A-2));
else
ans+=(A*(A-1)*(A-2))/3;
}
cout<<ans;}
else{
for(int i=1;i<N+1;i++)
DFS(i);
for(ll i=1;i<N+1;i++){
A=B=0;
for(ll f:grafo[i]){
A+=E[{i,f}];
B+=E[{i,f}]*E[{i,f}];
}
A=A*A;
ans+=A-B;
}
cout<<ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
910 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
910 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1113 ms |
463852 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
569 ms |
7800 KB |
Output is correct |
2 |
Correct |
559 ms |
7940 KB |
Output is correct |
3 |
Correct |
561 ms |
7804 KB |
Output is correct |
4 |
Correct |
585 ms |
8040 KB |
Output is correct |
5 |
Correct |
592 ms |
7944 KB |
Output is correct |
6 |
Correct |
587 ms |
8072 KB |
Output is correct |
7 |
Correct |
592 ms |
7964 KB |
Output is correct |
8 |
Correct |
586 ms |
7772 KB |
Output is correct |
9 |
Correct |
593 ms |
8056 KB |
Output is correct |
10 |
Incorrect |
464 ms |
7900 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1047 ms |
25012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
564 ms |
7900 KB |
Output is correct |
2 |
Correct |
571 ms |
8064 KB |
Output is correct |
3 |
Execution timed out |
1119 ms |
1048580 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1079 ms |
24848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
910 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
910 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |