Submission #656862

# Submission time Handle Problem Language Result Execution time Memory
656862 2022-11-08T12:15:13 Z benjaminkleyn Duathlon (APIO18_duathlon) C++17
49 / 100
123 ms 28696 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int max_n = 100001;

int n, m;
vector<int> g[max_n];

bool vis[max_n] = {false};
int ti[max_n], lo[max_n], timer = 0;

ll N;
ll sz[max_n];
ll ans = 0;

vector<int> G[4 * max_n];
int bcc_cnt = 0;

stack<int> s;
void dfs1(int u, int p = -1)
{
    vis[u] = true;
    ti[u] = lo[u] = timer++;
    N++;
    s.push(u);
    for (int v : g[u])
        if (v != p)
        {
            if (vis[v])
                lo[u] = min(lo[u], ti[v]);
            else
            {
                dfs1(v, u);
                lo[u] = min(lo[u], lo[v]);

                // if u is a cutpoint, or u is the root node
                if (lo[v] >= ti[u])
                {
                    bcc_cnt++;
                    G[u].push_back(n + bcc_cnt);
                    do
                    {
                        G[n + bcc_cnt].push_back(s.top());
                        s.pop();
                    } while (G[n + bcc_cnt].back() != v);
                }
            }
        }
}

ll dfs2(int u, int p = -1)
{
    // count only nodes that were in original graph,
    // not representative nodes of biconnected components.
    sz[u] = (u <= n);
    for (int v : G[u])
    {
        sz[u] += dfs2(v, u);
        // (if u is a representative node of a bcc)
        if (u > n)
            ans -= G[u].size() * sz[v] * (sz[v] - 1);
        // G[u].size() = the number of nodes in this bcc.
        // sz[v] = the number of nodes in subtree of v in bcc-graph.
    }
    // same as above, but considering everything that is not in the subtree of u.
    if (u > n)
        ans -= G[u].size() * (N - sz[u]) * (N - sz[u] - 1);

    return sz[u];
}

int main()
{
    cin >> n >> m;
    for (int i = 0, a, b; i < m; i++)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    for (int i = 1; i <= n; i++)
        if (!vis[i])
        {
            N = 0;
            dfs1(i);
            ans += N * (N - 1) * (N - 2);
            dfs2(i);
        }

    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 12044 KB Output is correct
4 Correct 6 ms 11960 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 8 ms 11992 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 9 ms 11988 KB Output is correct
16 Correct 9 ms 12044 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 12012 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 6 ms 11988 KB Output is correct
24 Correct 7 ms 11960 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 11988 KB Output is correct
27 Correct 7 ms 12068 KB Output is correct
28 Correct 6 ms 11988 KB Output is correct
29 Correct 7 ms 11988 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 11988 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 12044 KB Output is correct
4 Correct 6 ms 11960 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 8 ms 11992 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 9 ms 11988 KB Output is correct
16 Correct 9 ms 12044 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 12012 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 6 ms 11988 KB Output is correct
24 Correct 7 ms 11960 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 11988 KB Output is correct
27 Correct 7 ms 12068 KB Output is correct
28 Correct 6 ms 11988 KB Output is correct
29 Correct 7 ms 11988 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 11988 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 6 ms 11952 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 6 ms 11988 KB Output is correct
39 Correct 6 ms 11988 KB Output is correct
40 Correct 6 ms 11952 KB Output is correct
41 Correct 6 ms 11988 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 6 ms 11988 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 7 ms 12032 KB Output is correct
46 Correct 7 ms 11996 KB Output is correct
47 Correct 7 ms 11988 KB Output is correct
48 Correct 9 ms 11988 KB Output is correct
49 Correct 6 ms 11988 KB Output is correct
50 Correct 6 ms 11988 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 11988 KB Output is correct
53 Correct 6 ms 11988 KB Output is correct
54 Correct 6 ms 11988 KB Output is correct
55 Correct 6 ms 11988 KB Output is correct
56 Correct 6 ms 11988 KB Output is correct
57 Correct 6 ms 11960 KB Output is correct
58 Correct 6 ms 11988 KB Output is correct
59 Correct 7 ms 11988 KB Output is correct
60 Correct 6 ms 12068 KB Output is correct
61 Correct 6 ms 11988 KB Output is correct
62 Correct 6 ms 11988 KB Output is correct
63 Correct 7 ms 12072 KB Output is correct
64 Correct 7 ms 11988 KB Output is correct
65 Correct 6 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 28696 KB Output is correct
2 Correct 115 ms 28628 KB Output is correct
3 Correct 118 ms 26520 KB Output is correct
4 Incorrect 123 ms 27524 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 9 ms 12116 KB Output is correct
3 Correct 7 ms 12116 KB Output is correct
4 Correct 7 ms 12244 KB Output is correct
5 Correct 7 ms 12244 KB Output is correct
6 Correct 7 ms 12116 KB Output is correct
7 Correct 7 ms 12244 KB Output is correct
8 Correct 7 ms 12136 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 9 ms 12156 KB Output is correct
11 Correct 7 ms 12048 KB Output is correct
12 Correct 8 ms 12116 KB Output is correct
13 Correct 8 ms 12060 KB Output is correct
14 Correct 9 ms 12164 KB Output is correct
15 Correct 8 ms 12116 KB Output is correct
16 Correct 7 ms 12116 KB Output is correct
17 Correct 7 ms 12116 KB Output is correct
18 Correct 6 ms 12164 KB Output is correct
19 Correct 8 ms 12176 KB Output is correct
20 Correct 7 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 21676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12116 KB Output is correct
2 Correct 10 ms 12120 KB Output is correct
3 Correct 8 ms 12116 KB Output is correct
4 Correct 8 ms 12116 KB Output is correct
5 Correct 9 ms 12116 KB Output is correct
6 Correct 8 ms 12040 KB Output is correct
7 Correct 8 ms 12116 KB Output is correct
8 Correct 8 ms 12116 KB Output is correct
9 Correct 7 ms 12116 KB Output is correct
10 Correct 7 ms 12116 KB Output is correct
11 Correct 6 ms 12116 KB Output is correct
12 Correct 7 ms 12116 KB Output is correct
13 Correct 7 ms 12116 KB Output is correct
14 Correct 7 ms 12116 KB Output is correct
15 Correct 7 ms 12096 KB Output is correct
16 Correct 7 ms 12052 KB Output is correct
17 Correct 7 ms 12116 KB Output is correct
18 Correct 7 ms 12116 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 8 ms 12024 KB Output is correct
21 Correct 7 ms 12116 KB Output is correct
22 Correct 7 ms 12120 KB Output is correct
23 Correct 7 ms 12072 KB Output is correct
24 Correct 9 ms 12152 KB Output is correct
25 Correct 7 ms 12044 KB Output is correct
26 Correct 6 ms 12100 KB Output is correct
27 Correct 9 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 119 ms 21564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 12044 KB Output is correct
4 Correct 6 ms 11960 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 8 ms 11992 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 9 ms 11988 KB Output is correct
16 Correct 9 ms 12044 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 12012 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 6 ms 11988 KB Output is correct
24 Correct 7 ms 11960 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 11988 KB Output is correct
27 Correct 7 ms 12068 KB Output is correct
28 Correct 6 ms 11988 KB Output is correct
29 Correct 7 ms 11988 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 11988 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 6 ms 11952 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 6 ms 11988 KB Output is correct
39 Correct 6 ms 11988 KB Output is correct
40 Correct 6 ms 11952 KB Output is correct
41 Correct 6 ms 11988 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 6 ms 11988 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 7 ms 12032 KB Output is correct
46 Correct 7 ms 11996 KB Output is correct
47 Correct 7 ms 11988 KB Output is correct
48 Correct 9 ms 11988 KB Output is correct
49 Correct 6 ms 11988 KB Output is correct
50 Correct 6 ms 11988 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 11988 KB Output is correct
53 Correct 6 ms 11988 KB Output is correct
54 Correct 6 ms 11988 KB Output is correct
55 Correct 6 ms 11988 KB Output is correct
56 Correct 6 ms 11988 KB Output is correct
57 Correct 6 ms 11960 KB Output is correct
58 Correct 6 ms 11988 KB Output is correct
59 Correct 7 ms 11988 KB Output is correct
60 Correct 6 ms 12068 KB Output is correct
61 Correct 6 ms 11988 KB Output is correct
62 Correct 6 ms 11988 KB Output is correct
63 Correct 7 ms 12072 KB Output is correct
64 Correct 7 ms 11988 KB Output is correct
65 Correct 6 ms 11988 KB Output is correct
66 Correct 6 ms 12088 KB Output is correct
67 Correct 7 ms 12116 KB Output is correct
68 Correct 7 ms 12116 KB Output is correct
69 Correct 7 ms 12168 KB Output is correct
70 Correct 10 ms 12116 KB Output is correct
71 Correct 9 ms 12140 KB Output is correct
72 Correct 9 ms 12116 KB Output is correct
73 Correct 7 ms 12116 KB Output is correct
74 Correct 8 ms 12088 KB Output is correct
75 Correct 7 ms 12104 KB Output is correct
76 Correct 6 ms 11988 KB Output is correct
77 Correct 7 ms 12116 KB Output is correct
78 Correct 7 ms 12116 KB Output is correct
79 Correct 7 ms 12136 KB Output is correct
80 Correct 7 ms 12128 KB Output is correct
81 Correct 7 ms 12116 KB Output is correct
82 Correct 7 ms 12072 KB Output is correct
83 Correct 8 ms 12116 KB Output is correct
84 Correct 9 ms 12168 KB Output is correct
85 Correct 8 ms 12116 KB Output is correct
86 Correct 7 ms 12116 KB Output is correct
87 Correct 7 ms 12124 KB Output is correct
88 Correct 8 ms 12116 KB Output is correct
89 Correct 7 ms 12116 KB Output is correct
90 Correct 7 ms 12116 KB Output is correct
91 Correct 7 ms 12116 KB Output is correct
92 Correct 7 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 11988 KB Output is correct
3 Correct 7 ms 12044 KB Output is correct
4 Correct 6 ms 11960 KB Output is correct
5 Correct 6 ms 11988 KB Output is correct
6 Correct 6 ms 11988 KB Output is correct
7 Correct 6 ms 11988 KB Output is correct
8 Correct 6 ms 11988 KB Output is correct
9 Correct 6 ms 11988 KB Output is correct
10 Correct 8 ms 11992 KB Output is correct
11 Correct 6 ms 11988 KB Output is correct
12 Correct 7 ms 12004 KB Output is correct
13 Correct 6 ms 11988 KB Output is correct
14 Correct 6 ms 11988 KB Output is correct
15 Correct 9 ms 11988 KB Output is correct
16 Correct 9 ms 12044 KB Output is correct
17 Correct 6 ms 11988 KB Output is correct
18 Correct 6 ms 12012 KB Output is correct
19 Correct 7 ms 11988 KB Output is correct
20 Correct 7 ms 11988 KB Output is correct
21 Correct 7 ms 11988 KB Output is correct
22 Correct 6 ms 11988 KB Output is correct
23 Correct 6 ms 11988 KB Output is correct
24 Correct 7 ms 11960 KB Output is correct
25 Correct 6 ms 11988 KB Output is correct
26 Correct 6 ms 11988 KB Output is correct
27 Correct 7 ms 12068 KB Output is correct
28 Correct 6 ms 11988 KB Output is correct
29 Correct 7 ms 11988 KB Output is correct
30 Correct 7 ms 11988 KB Output is correct
31 Correct 7 ms 11988 KB Output is correct
32 Correct 8 ms 11988 KB Output is correct
33 Correct 6 ms 11988 KB Output is correct
34 Correct 6 ms 11988 KB Output is correct
35 Correct 6 ms 11988 KB Output is correct
36 Correct 6 ms 11952 KB Output is correct
37 Correct 6 ms 11988 KB Output is correct
38 Correct 6 ms 11988 KB Output is correct
39 Correct 6 ms 11988 KB Output is correct
40 Correct 6 ms 11952 KB Output is correct
41 Correct 6 ms 11988 KB Output is correct
42 Correct 6 ms 11988 KB Output is correct
43 Correct 6 ms 11988 KB Output is correct
44 Correct 7 ms 11988 KB Output is correct
45 Correct 7 ms 12032 KB Output is correct
46 Correct 7 ms 11996 KB Output is correct
47 Correct 7 ms 11988 KB Output is correct
48 Correct 9 ms 11988 KB Output is correct
49 Correct 6 ms 11988 KB Output is correct
50 Correct 6 ms 11988 KB Output is correct
51 Correct 6 ms 11988 KB Output is correct
52 Correct 6 ms 11988 KB Output is correct
53 Correct 6 ms 11988 KB Output is correct
54 Correct 6 ms 11988 KB Output is correct
55 Correct 6 ms 11988 KB Output is correct
56 Correct 6 ms 11988 KB Output is correct
57 Correct 6 ms 11960 KB Output is correct
58 Correct 6 ms 11988 KB Output is correct
59 Correct 7 ms 11988 KB Output is correct
60 Correct 6 ms 12068 KB Output is correct
61 Correct 6 ms 11988 KB Output is correct
62 Correct 6 ms 11988 KB Output is correct
63 Correct 7 ms 12072 KB Output is correct
64 Correct 7 ms 11988 KB Output is correct
65 Correct 6 ms 11988 KB Output is correct
66 Correct 115 ms 28696 KB Output is correct
67 Correct 115 ms 28628 KB Output is correct
68 Correct 118 ms 26520 KB Output is correct
69 Incorrect 123 ms 27524 KB Output isn't correct
70 Halted 0 ms 0 KB -