답안 #876015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876015 2023-11-21T05:26:11 Z NeroZein 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
60 ms 45192 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

const int N = 1e5 + 5; 

int num; 
int a[N];
int id[N];
int sz[N];
bool c[N]; 
long long ans; 
stack<int> stk; 
int vis[N], low[N];
bool is_cutpoint[N];
vector<int> g[N], t[N]; 
vector<vector<int>> bcc; 

void dfs(int v, int p) {
  vis[v] = low[v] = ++num; 
  stk.push(v); 
  for (int u : g[v]) {
    if (u == p) {
      continue;
    }
    if (vis[u]) {
      low[v] = min(low[v], vis[u]);
      continue; 
    }
    dfs(u, v); 
    low[v] = min(low[v], low[u]);
    if (low[u] >= vis[v]) {
      is_cutpoint[v] = true; 
      bcc.push_back({}); 
      bcc.back().push_back(v);
      while (bcc.back().back() != u) {
        bcc.back().push_back(stk.top());
        stk.pop(); 
      }
    }
  }
}

void dfs2(int v, int p) {
  vis[v] = true; 
  sz[v] = a[v]; 
  for (int u : t[v]) {
    if (u == p) continue; 
    dfs2(u, v);
    sz[v] += sz[u]; 
  }
}

void dfs3(int v, int p, int n) {
  for (int u : t[v]) {
    if (c[v]) {
      int x = (u == p ? n - sz[v] : sz[u]);
      ans -= (long long) x * (n - x) * (n - x - 1); 
    }
    if (u != p) {
      dfs3(u, v, n); 
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u); 
  }
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      dfs(i, i); 
      if (g[i].size() <= 1) {
        is_cutpoint[i] = false; 
      }
    }
  }
  int idd = 0; 
  for (int i = 1; i <= n; ++i) {
    if (is_cutpoint[i]) {
      c[idd] = true; 
      a[idd] = 1; 
      id[i] = idd++; 
    }
  }
  for (int i = 0; i < (int) bcc.size(); ++i) {
    vector<int>& comp = bcc[i];
    int cur = idd++;
    for (int v : comp) {
      if (is_cutpoint[v]) {
        t[id[v]].push_back(cur);
        t[cur].push_back(id[v]); 
      } else {
        id[v] = cur; 
        a[cur]++; 
      }
    }
  }
  memset(vis, 0, sizeof vis); 
  for (int i = 0; i < idd; ++i) {
    if (!vis[i]) {
      dfs2(i, i);
      dfs3(i, i, sz[i]); 
      ans += (long long) sz[i] * (sz[i] - 1) * (sz[i] - 2); 
    }
  }
  cout << ans << '\n'; 
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Incorrect 2 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Incorrect 2 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 21928 KB Output is correct
2 Correct 35 ms 21724 KB Output is correct
3 Runtime error 60 ms 43660 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 56 ms 44544 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 45192 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Incorrect 2 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Incorrect 2 ms 6748 KB Output isn't correct
8 Halted 0 ms 0 KB -