Submission #369830

# Submission time Handle Problem Language Result Execution time Memory
369830 2021-02-22T14:33:35 Z abc864197532 Duathlon (APIO18_duathlon) C++17
31 / 100
216 ms 45664 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define test(x) cout << "Line(" << __LINE__ << ") " #x << ' ' << x << endl
#define printv(x) {\
	for (auto i : x) cout << i << ' ';\
	cout << endl;\
}
#define pii pair <int, int>
#define pll pair <lli, lli>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<typename A, typename B>
ostream& operator << (ostream& o, pair<A, B> a){
    return o << a.X << ' ' << a.Y;
}
template<typename A, typename B>
istream& operator >> (istream& o, pair<A, B> &a){
    return o >> a.X >> a.Y;
}
const int mod = 1e9 + 7, abc = 864197532, N = 100000, logN = 17, K = 333;

vector <int> adj[N], bcc[N], cnt[N];
int low[N], dep[N], nbcc = 0;
bool vis[N], cut[N];
stack <int> stk;

void dfs(int v, int pa) {
    vis[v] = true;
    low[v] = dep[v] = ~pa ? dep[pa] + 1 : 0;
    stk.push(v);
    int ch = 0;
    for (int u : adj[v]) if (u != pa) {
        if (vis[u]) low[v] = min(low[v], dep[u]);
        else {
            dfs(u, v);
            low[v] = min(low[v], low[u]);
            ch++;
            if (low[u] >= dep[v]) {
                cut[v] = true;
                int x;
                do {
                    x = stk.top(); stk.pop();
                    bcc[x].pb(nbcc);
                    cnt[nbcc].pb(x);
                } while (x != u);
                cnt[nbcc].pb(v);
                bcc[v].pb(nbcc++);
            }
        }
    }
    if (pa == -1 && ch < 2) cut[v] = false;
}

vector <int> newadj[N * 2];
bool vis2[N * 2];
int sz[N * 2], p[N * 2], val[N * 2];
vector <int> cc;

lli C2(int n) {
    return 1ll * n * (n - 1);
}

void dfs2(int v, int pa) {
    sz[v] = val[v];
    vis2[v] = true;
    p[v] = pa;
    cc.pb(v);
    for (int u : newadj[v]) if (u != pa) {
        dfs2(u, v);
        sz[v] += sz[u];
    }
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0, u, v; i < m; ++i) {
        cin >> u >> v, --u, --v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for (int i = 0; i < n; ++i) if (!vis[i]) dfs(i, -1);
    for (int i = 0; i < n; ++i) if (cut[i]) {
        for (int j : bcc[i]) {
            newadj[i].pb(j + N);
            newadj[j + N].pb(i);
        }
    }
    for (int i = 0; i < nbcc; ++i) {
        for (int j : cnt[i]) {
            if (!cut[j]) val[i + N]++;
        }
    }
    for (int i = 0; i < n; ++i) if (cut[i]) val[i]++;
    lli ans = 0;
    for (int i = N; i < nbcc + N; ++i) if (!vis2[i]) {
        dfs2(i, -1);
        int m = sz[i];
        if (m <= 2) continue;
        ans += C2(m - 1) * m;
        for (int j : cc) {
            if (j < n) {
                for (int k : newadj[j]) {
                    if (k == p[j]) ans -= C2(m - sz[j] - val[k]);
                    else ans -= C2(sz[k] - val[k]);
                }
            } else {
                for (int k : newadj[j]) {
                    if (k == p[j]) ans -= C2(m - sz[j]) * val[j];
                    else ans -= C2(sz[k]) * val[j];
                }
            }
        }
        cc.clear();
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 9 ms 12140 KB Output is correct
6 Correct 9 ms 12140 KB Output is correct
7 Incorrect 9 ms 12140 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 9 ms 12140 KB Output is correct
6 Correct 9 ms 12140 KB Output is correct
7 Incorrect 9 ms 12140 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 31844 KB Output is correct
2 Correct 111 ms 32100 KB Output is correct
3 Correct 155 ms 34148 KB Output is correct
4 Correct 122 ms 33380 KB Output is correct
5 Correct 124 ms 30460 KB Output is correct
6 Correct 160 ms 35428 KB Output is correct
7 Correct 163 ms 31336 KB Output is correct
8 Correct 165 ms 33124 KB Output is correct
9 Correct 162 ms 29932 KB Output is correct
10 Correct 145 ms 29680 KB Output is correct
11 Correct 104 ms 25836 KB Output is correct
12 Correct 107 ms 25836 KB Output is correct
13 Correct 93 ms 25068 KB Output is correct
14 Correct 101 ms 24832 KB Output is correct
15 Correct 73 ms 23020 KB Output is correct
16 Correct 67 ms 22764 KB Output is correct
17 Correct 11 ms 13548 KB Output is correct
18 Correct 11 ms 13548 KB Output is correct
19 Correct 12 ms 13560 KB Output is correct
20 Correct 11 ms 13548 KB Output is correct
21 Correct 11 ms 13568 KB Output is correct
22 Correct 11 ms 13548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12268 KB Output is correct
2 Correct 9 ms 12396 KB Output is correct
3 Correct 10 ms 12396 KB Output is correct
4 Correct 10 ms 12540 KB Output is correct
5 Correct 9 ms 12396 KB Output is correct
6 Correct 10 ms 12396 KB Output is correct
7 Correct 10 ms 12524 KB Output is correct
8 Correct 10 ms 12396 KB Output is correct
9 Correct 10 ms 12396 KB Output is correct
10 Correct 9 ms 12396 KB Output is correct
11 Correct 11 ms 12396 KB Output is correct
12 Correct 9 ms 12268 KB Output is correct
13 Correct 9 ms 12268 KB Output is correct
14 Correct 10 ms 12268 KB Output is correct
15 Correct 9 ms 12288 KB Output is correct
16 Correct 9 ms 12396 KB Output is correct
17 Correct 9 ms 12268 KB Output is correct
18 Correct 9 ms 12268 KB Output is correct
19 Correct 9 ms 12268 KB Output is correct
20 Correct 9 ms 12396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 32360 KB Output is correct
2 Correct 166 ms 32360 KB Output is correct
3 Correct 159 ms 32360 KB Output is correct
4 Correct 163 ms 32364 KB Output is correct
5 Correct 187 ms 32360 KB Output is correct
6 Correct 216 ms 45664 KB Output is correct
7 Correct 197 ms 37088 KB Output is correct
8 Correct 189 ms 35808 KB Output is correct
9 Correct 187 ms 34920 KB Output is correct
10 Correct 160 ms 31724 KB Output is correct
11 Correct 166 ms 32620 KB Output is correct
12 Correct 156 ms 31600 KB Output is correct
13 Correct 165 ms 31600 KB Output is correct
14 Correct 141 ms 30132 KB Output is correct
15 Correct 131 ms 28780 KB Output is correct
16 Correct 72 ms 23916 KB Output is correct
17 Correct 86 ms 29800 KB Output is correct
18 Correct 86 ms 29920 KB Output is correct
19 Correct 87 ms 29852 KB Output is correct
20 Correct 87 ms 29804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12268 KB Output is correct
2 Correct 9 ms 12396 KB Output is correct
3 Incorrect 9 ms 12268 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 163 ms 32360 KB Output is correct
2 Correct 175 ms 32484 KB Output is correct
3 Incorrect 182 ms 31340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 9 ms 12140 KB Output is correct
6 Correct 9 ms 12140 KB Output is correct
7 Incorrect 9 ms 12140 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12140 KB Output is correct
2 Correct 8 ms 12140 KB Output is correct
3 Correct 8 ms 12140 KB Output is correct
4 Correct 8 ms 12140 KB Output is correct
5 Correct 9 ms 12140 KB Output is correct
6 Correct 9 ms 12140 KB Output is correct
7 Incorrect 9 ms 12140 KB Output isn't correct
8 Halted 0 ms 0 KB -