Submission #217698

# Submission time Handle Problem Language Result Execution time Memory
217698 2020-03-30T12:57:08 Z VEGAnn Duathlon (APIO18_duathlon) C++14
71 / 100
155 ms 19320 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define pii pair<int,int>
#define ft first
#define sd second
#define MP make_pair
using namespace std;
typedef long long ll;
const int N = 100100;
const int M = 200100;
const int oo = 2e9;
vector<int> g[N];
vector<pii> gr[N];
int n, m, tin[N], fup[N], tt = 0, U[M], V[M], pr[N], siz[N];
int nw_siz[N];
bool mrk[N], bridge[M], cutpoint[N], cp[N], used[N];
int f[(1 << 10)][10];
ll ans = 0, SZ;

void dfs(int v, int p){
    mrk[v] = 1;
    tin[v] = fup[v] = ++tt;

    for (int nm : g[v]){
        int u = (U[nm] == v ? V[nm] : U[nm]);

        if (u == p) continue;

        if (mrk[u])
            fup[v] = min(fup[v], tin[u]);
        else {
            dfs(u, v);
            fup[v] = min(fup[v], fup[u]);

            if (fup[u] > tin[v])
                bridge[nm] = 1;
        }
    }
}

int get(int x) { return (x == pr[x] ? x : pr[x] = get(pr[x])); }

void dfs1(int v, int p){
    nw_siz[v] = siz[v];
    mrk[v] = 1;

    for (pii u : gr[v]){
        if (u.sd == p) continue;

        dfs1(u.sd, v);
        nw_siz[v] += nw_siz[u.sd];
    }
}

void dfs2(int v, int p){
    ans += ll(siz[v]) * (ll(siz[v]) - 1ll) * (ll(siz[v]) - 2ll) / 2ll; // first

    ans += (SZ - ll(siz[v])) * (ll(siz[v]) - 1ll) * (ll(siz[v]) - 1ll);

    ll sum = 0ll;

    for (int it = 0; it < sz(gr[v]); ){

        int j = it;
        ll sim = 0;

        while (j < sz(gr[v]) && gr[v][it].ft == gr[v][j].ft){
            int u = gr[v][j].sd;
            if (u != p) {
                dfs2(u, v);
                ans += sim * ll(nw_siz[u]);
                sim += ll(nw_siz[u]);
            } else {
                ans += sim * (SZ - ll(nw_siz[v]));
                sim += (SZ - ll(nw_siz[v]));
            }
            j++;
        }

        ans += sum * ll(siz[v]) * sim;

        sum += sim;

        it = j;
    }
}

void search_cutpoint(int v, int p){
    mrk[v] = 1;
    tin[v] = fup[v] = ++tt;
    int children = 0;

    for (int nm : g[v]){
        int u = (U[nm] == v ? V[nm] : U[nm]);

        if (u == p) continue;

        if (mrk[u])
            fup[v] = min(fup[v], tin[u]);
        else {
            children++;
            search_cutpoint(u, v);
            fup[v] = min(fup[v], fup[u]);

            if (fup[u] >= tin[v] && p >= 0){
                cutpoint[v] = 1;
            }
        }
    }

    if (p < 0 && children > 1)
        cutpoint[v] = 1;
}

void last_dfs(int v){
    if (cp[v] || used[v]) return;
    used[v] = 1;
    ans++;

    for (int nm : g[v]){
        int u = (U[nm] == v ? V[nm] : U[nm]);
        last_dfs(u);
    }
}

void dfser(int v, int p, int st){
    if (mrk[v]) return;
    mrk[v] = 1;

    if (cutpoint[v])
        cp[v] = 1;

    if (v != st){
        fill(used, used + n, 0);
        used[v] = 1;

        for (int nm : g[v]){
            int u = (U[nm] == v ? V[nm] : U[nm]);
            last_dfs(u);
        }
    }

    for (int nm : g[v]){
        int u = (U[nm] == v ? V[nm] : U[nm]);

        dfser(u, v, st);
    }

    if (cutpoint[v])
        cp[v] = 0;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

//    freopen("in.txt","r",stdin);

    cin >> n >> m;

    for (int i = 0; i < m; i++){
        cin >> U[i] >> V[i];
        U[i]--; V[i]--;

        g[U[i]].PB(i);
        g[V[i]].PB(i);
    }

    if (n <= 10 && m <= 100){

        for (int st = 0; st < n; st++)
        for (int md = 0; md < n; md++)
        for (int ed = 0; ed < n; ed++) {

            if (st == ed || st == md || ed == md) continue;

            tt++;
            f[(1 << st)][st] = tt;
            bool was = 0;

            for (int msk = 0; msk < (1 << n); msk++)
            for (int lst = 0; lst < n; lst++){
                if (f[msk][lst] < tt) continue;

                if ((msk & (1 << md)) && (msk & (1 << ed)))
                    was = 1;

                for (int nm : g[lst]){
                    int u = (U[nm] == lst ? V[nm] : U[nm]);

                    if (msk & (1 << u)) continue;

                    if (u == ed && (msk & (1 << md)))
                        f[msk | (1 << u)][u] = tt;
                    else if (u != ed)
                        f[msk | (1 << u)][u] = tt;
                }
            }

            ans += was;
        }

        cout << ans;

        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (!mrk[i])
            dfs(i, -1);

        pr[i] = i;
        siz[i] = 1;
    }


    for (int i = 0; i < m; i++) {
        if (bridge[i]) continue;

        int x = get(U[i]), y = get(V[i]);

        if (x == y) continue;

        pr[x] = y;
        siz[y] += siz[x];
    }

    for (int i = 0; i < m; i++)
        if (bridge[i]){
            int x = get(U[i]), y = get(V[i]);

            gr[x].PB(MP(U[i], y));
            gr[y].PB(MP(V[i], x));
        }

    fill(mrk, mrk + n, 0);
    for (int i = 0; i < n; i++)
        if (sz(gr[i])){
            sort(all(gr[i]));
        }

    for (int i = 0; i < n; i++){
        if (get(i) != i) continue;
        if (mrk[i]) continue;

        dfs1(i, -1);
        SZ = nw_siz[i];
        dfs2(i, -1);
    }

    cout << ans * 2;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 15 ms 5120 KB Output is correct
7 Correct 15 ms 5248 KB Output is correct
8 Correct 19 ms 5120 KB Output is correct
9 Correct 65 ms 5120 KB Output is correct
10 Correct 114 ms 5120 KB Output is correct
11 Correct 15 ms 5120 KB Output is correct
12 Correct 14 ms 5120 KB Output is correct
13 Correct 15 ms 5120 KB Output is correct
14 Correct 15 ms 5120 KB Output is correct
15 Correct 16 ms 5120 KB Output is correct
16 Correct 14 ms 5120 KB Output is correct
17 Correct 16 ms 5120 KB Output is correct
18 Correct 15 ms 5120 KB Output is correct
19 Correct 15 ms 5120 KB Output is correct
20 Correct 14 ms 5120 KB Output is correct
21 Correct 15 ms 5120 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 11 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 11 ms 5120 KB Output is correct
26 Correct 14 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 13 ms 5120 KB Output is correct
29 Correct 15 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 14 ms 5120 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 14 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 15 ms 5120 KB Output is correct
7 Correct 15 ms 5248 KB Output is correct
8 Correct 19 ms 5120 KB Output is correct
9 Correct 65 ms 5120 KB Output is correct
10 Correct 114 ms 5120 KB Output is correct
11 Correct 15 ms 5120 KB Output is correct
12 Correct 14 ms 5120 KB Output is correct
13 Correct 15 ms 5120 KB Output is correct
14 Correct 15 ms 5120 KB Output is correct
15 Correct 16 ms 5120 KB Output is correct
16 Correct 14 ms 5120 KB Output is correct
17 Correct 16 ms 5120 KB Output is correct
18 Correct 15 ms 5120 KB Output is correct
19 Correct 15 ms 5120 KB Output is correct
20 Correct 14 ms 5120 KB Output is correct
21 Correct 15 ms 5120 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 11 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 11 ms 5120 KB Output is correct
26 Correct 14 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 13 ms 5120 KB Output is correct
29 Correct 15 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 14 ms 5120 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 14 ms 5120 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 7 ms 5120 KB Output is correct
38 Incorrect 7 ms 5120 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 18424 KB Output is correct
2 Correct 83 ms 18424 KB Output is correct
3 Correct 110 ms 16632 KB Output is correct
4 Correct 93 ms 17784 KB Output is correct
5 Correct 89 ms 14712 KB Output is correct
6 Correct 103 ms 15992 KB Output is correct
7 Correct 113 ms 14840 KB Output is correct
8 Correct 99 ms 15224 KB Output is correct
9 Correct 96 ms 13944 KB Output is correct
10 Correct 94 ms 14200 KB Output is correct
11 Correct 75 ms 12536 KB Output is correct
12 Correct 73 ms 12536 KB Output is correct
13 Correct 68 ms 12536 KB Output is correct
14 Correct 67 ms 12280 KB Output is correct
15 Correct 53 ms 12024 KB Output is correct
16 Correct 52 ms 11768 KB Output is correct
17 Correct 9 ms 7168 KB Output is correct
18 Correct 9 ms 7168 KB Output is correct
19 Correct 12 ms 7296 KB Output is correct
20 Correct 12 ms 7168 KB Output is correct
21 Correct 10 ms 7168 KB Output is correct
22 Correct 9 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5120 KB Output is correct
2 Correct 7 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 5248 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 10 ms 5248 KB Output is correct
8 Correct 7 ms 5248 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 7 ms 5120 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5120 KB Output is correct
17 Correct 7 ms 5248 KB Output is correct
18 Correct 8 ms 5248 KB Output is correct
19 Correct 8 ms 5248 KB Output is correct
20 Correct 7 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 14968 KB Output is correct
2 Correct 103 ms 14960 KB Output is correct
3 Correct 104 ms 14972 KB Output is correct
4 Correct 123 ms 15096 KB Output is correct
5 Correct 99 ms 14968 KB Output is correct
6 Correct 127 ms 19320 KB Output is correct
7 Correct 123 ms 18168 KB Output is correct
8 Correct 120 ms 17272 KB Output is correct
9 Correct 121 ms 16480 KB Output is correct
10 Correct 101 ms 14968 KB Output is correct
11 Correct 99 ms 14968 KB Output is correct
12 Correct 98 ms 14968 KB Output is correct
13 Correct 101 ms 14968 KB Output is correct
14 Correct 86 ms 14584 KB Output is correct
15 Correct 78 ms 14072 KB Output is correct
16 Correct 51 ms 12280 KB Output is correct
17 Correct 71 ms 15472 KB Output is correct
18 Correct 71 ms 15464 KB Output is correct
19 Correct 71 ms 15456 KB Output is correct
20 Correct 71 ms 15464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 7 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 7 ms 5120 KB Output is correct
9 Correct 7 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 7 ms 5248 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5248 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 7 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 7 ms 5248 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 7 ms 5120 KB Output is correct
26 Correct 7 ms 5120 KB Output is correct
27 Correct 7 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 14972 KB Output is correct
2 Correct 107 ms 14808 KB Output is correct
3 Correct 155 ms 13736 KB Output is correct
4 Correct 95 ms 12792 KB Output is correct
5 Correct 86 ms 11968 KB Output is correct
6 Correct 83 ms 11768 KB Output is correct
7 Correct 82 ms 11640 KB Output is correct
8 Correct 101 ms 11384 KB Output is correct
9 Correct 77 ms 11384 KB Output is correct
10 Correct 81 ms 11384 KB Output is correct
11 Correct 76 ms 11256 KB Output is correct
12 Correct 75 ms 11384 KB Output is correct
13 Correct 77 ms 11384 KB Output is correct
14 Correct 75 ms 12792 KB Output is correct
15 Correct 122 ms 16632 KB Output is correct
16 Correct 117 ms 16248 KB Output is correct
17 Correct 112 ms 16760 KB Output is correct
18 Correct 105 ms 15096 KB Output is correct
19 Correct 104 ms 12792 KB Output is correct
20 Correct 93 ms 12780 KB Output is correct
21 Correct 104 ms 12840 KB Output is correct
22 Correct 85 ms 12408 KB Output is correct
23 Correct 77 ms 12024 KB Output is correct
24 Correct 104 ms 13936 KB Output is correct
25 Correct 97 ms 14196 KB Output is correct
26 Correct 106 ms 13296 KB Output is correct
27 Correct 94 ms 13304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 15 ms 5120 KB Output is correct
7 Correct 15 ms 5248 KB Output is correct
8 Correct 19 ms 5120 KB Output is correct
9 Correct 65 ms 5120 KB Output is correct
10 Correct 114 ms 5120 KB Output is correct
11 Correct 15 ms 5120 KB Output is correct
12 Correct 14 ms 5120 KB Output is correct
13 Correct 15 ms 5120 KB Output is correct
14 Correct 15 ms 5120 KB Output is correct
15 Correct 16 ms 5120 KB Output is correct
16 Correct 14 ms 5120 KB Output is correct
17 Correct 16 ms 5120 KB Output is correct
18 Correct 15 ms 5120 KB Output is correct
19 Correct 15 ms 5120 KB Output is correct
20 Correct 14 ms 5120 KB Output is correct
21 Correct 15 ms 5120 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 11 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 11 ms 5120 KB Output is correct
26 Correct 14 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 13 ms 5120 KB Output is correct
29 Correct 15 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 14 ms 5120 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 14 ms 5120 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 7 ms 5120 KB Output is correct
38 Incorrect 7 ms 5120 KB Output isn't correct
39 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 5120 KB Output is correct
4 Correct 7 ms 4992 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 15 ms 5120 KB Output is correct
7 Correct 15 ms 5248 KB Output is correct
8 Correct 19 ms 5120 KB Output is correct
9 Correct 65 ms 5120 KB Output is correct
10 Correct 114 ms 5120 KB Output is correct
11 Correct 15 ms 5120 KB Output is correct
12 Correct 14 ms 5120 KB Output is correct
13 Correct 15 ms 5120 KB Output is correct
14 Correct 15 ms 5120 KB Output is correct
15 Correct 16 ms 5120 KB Output is correct
16 Correct 14 ms 5120 KB Output is correct
17 Correct 16 ms 5120 KB Output is correct
18 Correct 15 ms 5120 KB Output is correct
19 Correct 15 ms 5120 KB Output is correct
20 Correct 14 ms 5120 KB Output is correct
21 Correct 15 ms 5120 KB Output is correct
22 Correct 17 ms 5120 KB Output is correct
23 Correct 11 ms 5120 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 11 ms 5120 KB Output is correct
26 Correct 14 ms 5120 KB Output is correct
27 Correct 8 ms 5120 KB Output is correct
28 Correct 13 ms 5120 KB Output is correct
29 Correct 15 ms 5120 KB Output is correct
30 Correct 8 ms 5120 KB Output is correct
31 Correct 9 ms 5120 KB Output is correct
32 Correct 14 ms 5120 KB Output is correct
33 Correct 9 ms 5120 KB Output is correct
34 Correct 9 ms 5120 KB Output is correct
35 Correct 14 ms 5120 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 7 ms 5120 KB Output is correct
38 Incorrect 7 ms 5120 KB Output isn't correct
39 Halted 0 ms 0 KB -