Submission #59314

#TimeUsernameProblemLanguageResultExecution timeMemory
59314MatheusLealVDuathlon (APIO18_duathlon)C++17
8 / 100
152 ms11932 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 sz[N], tot = 0, ciclo; ll ultimo; void dfs(ll x) { ultimo = x; tot ++; ok[x] = 1; if(grafo[x].size() <= 1) ciclo = 0; 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 = 0LL; ciclo = 1; dfs(i); // cout<<i<<" "<<tot<<" "<<ciclo<<" "<<ans<<"\n"; 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...