Submission #864565

#TimeUsernameProblemLanguageResultExecution timeMemory
864565vnm06Duathlon (APIO18_duathlon)C++14
0 / 100
25 ms10588 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; long long n, m, brv=0, bv=0; bool used[300005]; vector<int> gr[300005]; bool dfs(int v) { used[v]=1; brv++; int brs=gr[v].size(); for(int i=0; i<brs; i++) { if(brv>2 && gr[v][i]==bv) return 1; if(used[gr[v][i]]) continue; return dfs(gr[v][i]); } return 0; } 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; bv=i; if(dfs(i)) 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...