Submission #59312

#TimeUsernameProblemLanguageResultExecution timeMemory
59312MatheusLealVDuathlon (APIO18_duathlon)C++17
0 / 100
157 ms19980 KiB
#include <bits/stdc++.h> #define N 100050 using namespace std; typedef long long ll; ll n, m, c, ans, ok[N]; vector<ll> grafo[N]; ll ini, mid, fim, sz[N], tot = 0; int ultimo; void dfs(int x) { ultimo = x; tot ++; ok[x] = 1; for(auto v: grafo[x]) { if(ok[v]) continue; dfs(v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(ll i = 1, a, b; i <= m; i++) { cin>>a>>b; grafo[a].push_back(b); grafo[b].push_back(a); } for(int i = 1; i <= n; i++) { if(ok[i]) continue; tot = 0; ultimo = i; dfs(i); int ciclo = 0; for(auto v: grafo[ultimo]) { if(v == i) ciclo = 1; } if(tot > 2 and ciclo) ans += (tot * (tot - 1) * (tot - 2)); else if(tot > 2 and !ciclo) ans += (tot * (tot - 1) * (tot - 2))/3; } cout<<ans<<"\n"; }
#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...