Submission #829928

# Submission time Handle Problem Language Result Execution time Memory
829928 2023-08-18T15:55:31 Z erray Duathlon (APIO18_duathlon) C++17
0 / 100
87 ms 35880 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG 
  #include "/home/eagle/ioi22/debug.h"
#else 
  #define debug(...) void(37)
#endif

struct DSU {
  vector<int> link;
  vector<int> size;
  DSU(int n) {
    size.resize(n, 1);
    link.resize(n);
    iota(link.begin(), link.end(), 0);
  }
  int get(int v) {
    return link[v] = (v == link[v] ? v : get(link[v]));
  }
  bool unite(int x, int y) {
    x = get(x), y = get(y);
    if (x == y) {
      return false;
    }
    link[y] = x;
    return true;
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  for (int i = 0; i < M; ++i) {
    int X, Y;
    cin >> X >> Y;
    --X, --Y;
    g[X].push_back(Y);
    g[Y].push_back(X);
  }
  vector<bool> vis(N);
  vector<int> d(N);
  vector<int> par(N, -1);
  DSU edges(N);
  vector<int> size(N, 1);
  vector<vector<int>> tree(N);
  vector<int> ord;
  function<void(int)> Dfs = [&](int v) {
    vis[v] = true;
    int back = d[v];
    for (auto u : g[v]) {
      if (!vis[u]) {
        d[u] = d[v] + 1;
        par[u] = v;
        Dfs(u);
        size[v] += size[u];
        tree[v].push_back(u);
        tree[u].push_back(v);
      } else {
        back = min(back, d[u]);
      }
    }
    int cv = v;
    while (d[cv] > back + 1 && edges.unite(cv, par[cv])) {
      cv = par[cv];
    }
    ord.push_back(v);
  };
  Dfs(0);
  vector<long long> cycle(N, 1);
  for (auto v : ord) {
    for (auto u : tree[v]) {
      if (u != par[v]) {
        cycle[v] += cycle[u] * (edges.get(u) == edges.get(v));
      }
    }
  }
  vector<long long> tot(N);
  for (int i = 1; i < N; ++i) {
    debug(edges.get(i));
    tot[edges.get(i)] += 1;
  }
  debug(cycle, tot);

  long long bad = 0;
  vector<int> ct(N);
  for (int i = 0; i < N; ++i) {
    if (i != 0) {
      ct[edges.get(i)] += 1;
    }
    for (auto u : tree[i]) {
      if (u != par[i]) {
        ct[edges.get(u)] += 1;
      }
    }
    debug(i);
    for (auto u : tree[i]) {
      long long s = size[u];
      long long cyc = (ct[edges.get(u)] >= 1 ? cycle[u] : 0);
      if (u == par[i]) {
        s = N - size[i];
        cyc = (ct[edges.get(i)] >= 1 ? tot[edges.get(i)] - cycle[edges.get(i)] + 1: 0);
      }
      long long dec = 1LL * s * (s - 1) - 1LL * cyc * (cyc - 1); 
      debug(s, cyc, dec);
      bad += dec;
    }
    ct[edges.get(i)] = 0;
    for (auto u : tree[i]) {
      ct[edges.get(u)] = 0;
    }
  }
  cout << (1LL * N * (N - 1) * (N - 2) - bad) << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 35880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Incorrect 1 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 15792 KB Output is correct
2 Correct 49 ms 15796 KB Output is correct
3 Correct 61 ms 15780 KB Output is correct
4 Correct 65 ms 15788 KB Output is correct
5 Correct 60 ms 15784 KB Output is correct
6 Correct 74 ms 26604 KB Output is correct
7 Correct 61 ms 22952 KB Output is correct
8 Correct 68 ms 21048 KB Output is correct
9 Correct 67 ms 19268 KB Output is correct
10 Incorrect 43 ms 14180 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 15820 KB Output is correct
2 Correct 55 ms 15704 KB Output is correct
3 Incorrect 83 ms 15696 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -