Submission #772000

#TimeUsernameProblemLanguageResultExecution timeMemory
772000CyberCowDuathlon (APIO18_duathlon)C++17
23 / 100
1082 ms1048576 KiB
//#include <bits/stdc++.h> #include <random> #include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <chrono> #define fr first #define sc second #define ad push_back using namespace std; using ll = long long; mt19937 rnd(348502); const int N = 300005; vector<ll> v[N]; ll sz[N]; ll color[N]; ll guyn = 0; ll chap; void Dfs(ll g) { sz[g] = 1; color[g] = guyn; for (auto to : v[g]) { if (color[to] == 0) { Dfs(to); sz[g] += sz[to]; } } } ll koxqan = 0; void Dfs1(ll g, ll guyn, int p) { koxqan += sz[g] * (chap - sz[g]); for (auto to : v[g]) { if (color[to] == guyn && to != p) { Dfs1(to, guyn, g); } } } void solve() { ll n, i, j, x, y, m; cin >> n >> m; vector<pair<ll, ll>> kox; for ( i = 0; i < m; i++) { cin >> x >> y; kox.push_back({ x, y }); v[x].push_back(y); v[y].push_back(x); } ll ans = 0; for ( i = 1; i <= n; i++) { if (color[i] == 0) { koxqan = 0; guyn++; Dfs(i); chap = sz[i]; Dfs1(i, guyn, -1); ans += koxqan - (chap * (chap - 1) / 2); } } cout << ans * 2; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll tt = 1; //cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

count_triplets.cpp: In function 'void solve()':
count_triplets.cpp:64:14: warning: unused variable 'j' [-Wunused-variable]
   64 |     ll n, i, j, x, y, m;
      |              ^
#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...