Submission #734332

# Submission time Handle Problem Language Result Execution time Memory
734332 2023-05-02T09:40:31 Z cig32 Duathlon (APIO18_duathlon) C++17
0 / 100
12 ms 19128 KB
#include "bits/stdc++.h"
#define int long long
using namespace std;
const int MAXN = 4e5 + 10;
vector<int> adj[MAXN];
vector<int> rst[MAXN]; // round-square tree
int n, m, cur;
int tin[MAXN], low[MAXN], vis[MAXN];
stack<int> stk;
int nxt;
int ans = 0;
void dfs(int node, int prv) {
  vis[node] = 1;
  tin[node] = ++cur;
  low[node] = tin[node];
  stk.push(node);
  for(int x: adj[node]) {
    if(x != prv) {
      if(!vis[x]) {
        dfs(x, node);
        low[node] = min(low[node], low[x]);
        if(low[x] >= tin[node]) {
          while(1) {
            int u = stk.top();
            stk.pop();
            rst[u].push_back(nxt);
            rst[nxt].push_back(u);
            if(u == x) break;
          }
          rst[node].push_back(nxt);
          rst[nxt].push_back(node);
          nxt++;
        }
      }
      else {
        low[node] = min(low[node], tin[x]);
      }
    }
  }
}
int w[MAXN];
int calc(int node, int prv) {
  int ret = (node <= n);
  vector<int> vt;
  for(int x: rst[node]) {
    if(x != prv) {
      int v = calc(x, node);
      ret += v;
      vt.push_back(v);
    }
  }
  vt.push_back(n - ret);
  int con = (node <= n ? 2 * (n-1) : 0);
  int ps = 0;
  for(int x: vt) {
    con += ps * x * 2;
    ps += x;
  }
  ans += con * w[node];
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  if(n == m) {
    cout << n * (n-1) * (n-2) << "\n";
  }
  else {
    cout << n * (n-1) * (n-2) / 3 << "\n";
  }
  return 0;
  for(int i=1; i<=m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  nxt = n+1;
  dfs(1, -1);
  m = nxt-1 - n;
  for(int i=1; i<=n; i++) w[i] = -1;
  for(int i=n+1; i<=n+m; i++) w[i] = rst[i].size();
  calc(1, -1);
  cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19028 KB Output is correct
2 Correct 11 ms 19120 KB Output is correct
3 Incorrect 9 ms 19128 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 19124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 19008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 19120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 19076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -