Submission #980790

#TimeUsernameProblemLanguageResultExecution timeMemory
980790UnforgettableplDuathlon (APIO18_duathlon)C++17
8 / 100
41 ms19292 KiB
#include <bits/stdc++.h> using namespace std; #define int long long vector<int> adj[200001]; bool visited[200001]; int DP[200001][4]; bool isCycle; int tot; void dfs(int x,int p){ if(visited[x]){ isCycle=true; return; } tot++; visited[x]=true; for(int&i:adj[x])if(i!=p)dfs(i,x); } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); for(auto&i:DP)i[0]=1; for(int i=1;i<=200000;i++)for(int j=1;j<=3;j++)DP[i][j]=DP[i-1][j]+DP[i-1][j-1]; int n,m; cin >> n >> m; for(int i=1;i<=m;i++){ int a,b;cin>>a>>b; adj[a].emplace_back(b); adj[b].emplace_back(a); } int ans = 0; for(int i=1;i<=n;i++)if(!visited[i]){ isCycle = false; tot = 0; dfs(i,0); if(isCycle)ans+=tot*(tot-1ll)*(tot-2ll); else ans+=2ll*DP[tot][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...