Submission #1070955

#TimeUsernameProblemLanguageResultExecution timeMemory
1070955pawnedDuathlon (APIO18_duathlon)C++17
0 / 100
37 ms10440 KiB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; const char nl = '\n'; void fastIO() { ios::sync_with_stdio(false); cin.tie(0); } const int MAX = 1e5 + 5; int N, M; bool vis[MAX]; vi adj[MAX]; vi inc; void dfs(int n) { vis[n] = true; inc.pb(n); for (int x : adj[n]) { if (!vis[x]) dfs(x); } } int main() { fastIO(); cin>>N>>M; for (int i = 0; i < M; i++) { int u, v; cin>>u>>v; u--; v--; adj[u].pb(v); adj[v].pb(u); } ll total = 0; for (int i = 0; i < N; i++) { if (!vis[i]) { inc.clear(); dfs(i); int K = inc.size(); total += (K * (K - 1) * (K - 2)) / 6; } } // cout<<"ANSWER: "; cout<<total * 2<<endl; }
#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...