Submission #296013

#TimeUsernameProblemLanguageResultExecution timeMemory
296013srvltDuathlon (APIO18_duathlon)C++14
10 / 100
24 ms512 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define all(x) begin(x), end(x) #define SZ(x) (int)(x).size() #define cps(x) sort(all(x)), (x).erase(unique(all(x)), end(x)) #define cps2(x, y) sort(all(x), y), (x).erase(unique(all(x)), end(x)) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int n0 = 1003; int n, m, root, used[n0], anc[n0], sz[n0], back, comp; vector <int> g[n0]; void dfs(int v, int p) { used[v] = 1; comp++; if (v != root) { if (p == root) anc[v] = v; else anc[v] = anc[p]; sz[anc[v]]++; } for (int to : g[v]) { if (to == p) continue; if (used[to] == 1 && to == root) { sz[anc[v]]--; back++; } if (!used[to]) dfs(to, v); } used[v] = 2; } int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].pb(y), g[y].pb(x); } ll res = 0; for (int i = 1; i <= n; i++) { root = i; comp = 0; memset(& used, 0, sizeof(used)); memset(& anc, 0, sizeof(anc)); memset(& sz, 0, sizeof(sz)); back = 0; dfs(i, -1); for (int j = 1; j <= n; j++) res += sz[j] * (comp - 1 - sz[j]); res += back * (comp - 2); } cout << res; }
#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...