답안 #876022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876022 2023-11-21T05:45:10 Z NeroZein 철인 이종 경기 (APIO18_duathlon) C++17
49 / 100
58 ms 48488 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]; 
int compsz[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) (compsz[u] - 1) * (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++;
    compsz[cur] = comp.size(); 
    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 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6744 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6744 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6744 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 1 ms 6796 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6744 KB Output is correct
42 Correct 1 ms 6744 KB Output is correct
43 Correct 2 ms 6792 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6792 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 2 ms 7000 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 1 ms 6748 KB Output is correct
53 Correct 1 ms 6748 KB Output is correct
54 Correct 1 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 1 ms 6748 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6748 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 22080 KB Output is correct
2 Correct 38 ms 21968 KB Output is correct
3 Runtime error 58 ms 44492 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 7004 KB Output is correct
5 Correct 2 ms 7004 KB Output is correct
6 Correct 2 ms 7004 KB Output is correct
7 Correct 2 ms 7004 KB Output is correct
8 Correct 2 ms 7004 KB Output is correct
9 Correct 2 ms 7252 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6744 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 1 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 48488 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6800 KB Output is correct
4 Correct 2 ms 6776 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6744 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 3 ms 7004 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6804 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 2 ms 6804 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 1 ms 6744 KB Output is correct
26 Correct 1 ms 6744 KB Output is correct
27 Correct 2 ms 7004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 57 ms 45076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6744 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6744 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 1 ms 6796 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6744 KB Output is correct
42 Correct 1 ms 6744 KB Output is correct
43 Correct 2 ms 6792 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6792 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 2 ms 7000 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 1 ms 6748 KB Output is correct
53 Correct 1 ms 6748 KB Output is correct
54 Correct 1 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 1 ms 6748 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6748 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 1 ms 6748 KB Output is correct
66 Correct 1 ms 6748 KB Output is correct
67 Correct 2 ms 6748 KB Output is correct
68 Correct 2 ms 6748 KB Output is correct
69 Correct 2 ms 6748 KB Output is correct
70 Correct 2 ms 6840 KB Output is correct
71 Correct 2 ms 6748 KB Output is correct
72 Correct 2 ms 6748 KB Output is correct
73 Correct 2 ms 6748 KB Output is correct
74 Correct 2 ms 6748 KB Output is correct
75 Correct 2 ms 6748 KB Output is correct
76 Correct 1 ms 6748 KB Output is correct
77 Correct 2 ms 6744 KB Output is correct
78 Correct 2 ms 6744 KB Output is correct
79 Correct 2 ms 6748 KB Output is correct
80 Correct 1 ms 6748 KB Output is correct
81 Correct 1 ms 6748 KB Output is correct
82 Correct 2 ms 6748 KB Output is correct
83 Correct 2 ms 6748 KB Output is correct
84 Correct 2 ms 6748 KB Output is correct
85 Correct 2 ms 6748 KB Output is correct
86 Correct 2 ms 6748 KB Output is correct
87 Correct 2 ms 6748 KB Output is correct
88 Correct 2 ms 6748 KB Output is correct
89 Correct 2 ms 6748 KB Output is correct
90 Correct 2 ms 6748 KB Output is correct
91 Correct 1 ms 6748 KB Output is correct
92 Correct 2 ms 6796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6744 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 1 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 1 ms 6748 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6748 KB Output is correct
14 Correct 1 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6748 KB Output is correct
18 Correct 2 ms 6748 KB Output is correct
19 Correct 1 ms 6744 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 1 ms 6744 KB Output is correct
23 Correct 1 ms 6748 KB Output is correct
24 Correct 1 ms 6748 KB Output is correct
25 Correct 1 ms 6748 KB Output is correct
26 Correct 1 ms 6748 KB Output is correct
27 Correct 1 ms 6748 KB Output is correct
28 Correct 1 ms 6748 KB Output is correct
29 Correct 1 ms 6748 KB Output is correct
30 Correct 1 ms 6748 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6744 KB Output is correct
37 Correct 1 ms 6748 KB Output is correct
38 Correct 1 ms 6796 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 1 ms 6744 KB Output is correct
42 Correct 1 ms 6744 KB Output is correct
43 Correct 2 ms 6792 KB Output is correct
44 Correct 1 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 1 ms 6792 KB Output is correct
48 Correct 1 ms 6748 KB Output is correct
49 Correct 2 ms 7000 KB Output is correct
50 Correct 2 ms 6748 KB Output is correct
51 Correct 1 ms 6748 KB Output is correct
52 Correct 1 ms 6748 KB Output is correct
53 Correct 1 ms 6748 KB Output is correct
54 Correct 1 ms 6748 KB Output is correct
55 Correct 1 ms 6748 KB Output is correct
56 Correct 1 ms 6748 KB Output is correct
57 Correct 1 ms 6748 KB Output is correct
58 Correct 1 ms 6748 KB Output is correct
59 Correct 1 ms 6748 KB Output is correct
60 Correct 1 ms 6748 KB Output is correct
61 Correct 1 ms 6748 KB Output is correct
62 Correct 2 ms 6748 KB Output is correct
63 Correct 1 ms 6748 KB Output is correct
64 Correct 2 ms 7004 KB Output is correct
65 Correct 1 ms 6748 KB Output is correct
66 Correct 35 ms 22080 KB Output is correct
67 Correct 38 ms 21968 KB Output is correct
68 Runtime error 58 ms 44492 KB Execution killed with signal 11
69 Halted 0 ms 0 KB -