Submission #1115776

#TimeUsernameProblemLanguageResultExecution timeMemory
1115776gustavo_dDuathlon (APIO18_duathlon)C++17
8 / 100
45 ms14236 KiB
// https://oj.uz/problem/view/APIO18_duathlon > p520 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5; vector<int> adj[MAXN]; bool vis[MAXN]; pair<int, bool> dfs(int v, int pai) { vis[v] = true; int sz = 1; bool cycle = false; for (int viz : adj[v]) { if (vis[viz]) { if (viz != pai) cycle = true; continue; } pair<int, int> res = dfs(viz, v); sz += res.first; if (res.second) cycle = true; } return {sz, cycle}; } ll qty(pair<int, bool> res) { int n = res.first; bool cycle = res.second; return (ll)(n) * (ll)(n - 1) * (ll)(n - 2) / (ll)(3 - 2*cycle); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i=0; i<m; i++) { int u, v; cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } ll ans = 0; for (int i=0; i<n; i++) { if (vis[i]) continue; // assert(i==0); ans += qty(dfs(i, -1)); } cout << ans << '\n'; 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...