Submission #975401

#TimeUsernameProblemLanguageResultExecution timeMemory
975401akacool445kDuathlon (APIO18_duathlon)C++14
0 / 100
69 ms14888 KiB
#include <bits/stdc++.h> // #include "jumps.h" using namespace std; // #define int long long #define ll long long #define ff first #define ss second #define pii pair <int, int> #define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL) const int inf = 1e9 + 9; const int mxn = 2e5 + 2; const int mod = 1e9 + 7; vector<vector<int>> adj(mxn); vector<int> chld(mxn); vector<bool> did(mxn); void dfs(int x) { if(did[x]) return; did[x] = 1; for(auto a : adj[x]) { if(!did[a]) { chld[x]++; dfs(a); chld[x] += chld[a]; } } } int main() { int n, m; cin >> n >> m; for(int i = 0; i < m; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } for(int i = 1; i <= n; i++) { dfs(i); } // for(int i = 1; i <= n; i++) { // cout << chld[i] << ' '; // } int ans = 0; for(int i = 1; i <= n; i++) { ans += chld[i] * (chld[i] - 1); } cout << ans; cout << '\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...