Submission #864566

#TimeUsernameProblemLanguageResultExecution timeMemory
864566vnm06Duathlon (APIO18_duathlon)C++14
8 / 100
34 ms15456 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; long long n, m, brv=0, sumst=0; bool used[300005]; vector<int> gr[300005]; void dfs(int v) { used[v]=1; brv++; int brs=gr[v].size(); sumst+=brs; for(int i=0; i<brs; i++) { if(used[gr[v][i]]) continue; dfs(gr[v][i]); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0; i<m; i++) { int v, u; cin>>v>>u; gr[v].push_back(u); gr[u].push_back(v); } long long ans=0; for(int i=1; i<=n; i++) { if(used[i]) continue; brv=0; sumst=0; dfs(i); if(sumst==2*brv) ans+=brv*(brv-1)*(brv-2); else ans+=brv*(brv-1)*(brv-2)/3; } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...