이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll>pil;
const int N=1e5+5;
int n, m, nn;
vector<int>g[N], nd;
bool mk[N];
void dfs(const int &v){
mk[v]=1;
nd.push_back(v);
for(int u: g[v]){
if(!mk[u])
dfs(u);
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
if(m>n)
return 0;
for(int i=0;i<m;++i){
int u, v;
cin>>u>>v;
g[--u].push_back(--v);
g[v].push_back(u);
}
ll ans=0;
for(int i=0;i<n;++i){
if(!mk[i]){
dfs(i);
nn=nd.size();
bool b=1;
for(int v: nd){
if(g[v].size()==1){
b=0;
break;
}
}
if(b)
ans+=1LL*nn*(nn-1)*(nn-2);
else
ans+=1LL*nn*(nn-1)*(nn-2)/3;
nd.clear();
}
}
cout<<ans<<'\n';
}
# | 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... |