이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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,C,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++;
C++;
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}]=C-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++)
if(!V[i]){
C=0;
DFSsub3(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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |