Submission #217647

# Submission time Handle Problem Language Result Execution time Memory
217647 2020-03-30T11:35:44 Z VEGAnn Duathlon (APIO18_duathlon) C++14
66 / 100
254 ms 20604 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];
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;
    }
}

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);
    }

    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 8 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Incorrect 8 ms 5120 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Incorrect 8 ms 5120 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 19704 KB Output is correct
2 Correct 112 ms 19832 KB Output is correct
3 Correct 181 ms 17856 KB Output is correct
4 Correct 132 ms 18936 KB Output is correct
5 Correct 136 ms 15952 KB Output is correct
6 Correct 153 ms 17272 KB Output is correct
7 Correct 182 ms 16092 KB Output is correct
8 Correct 150 ms 16376 KB Output is correct
9 Correct 144 ms 15196 KB Output is correct
10 Correct 177 ms 15352 KB Output is correct
11 Correct 108 ms 13688 KB Output is correct
12 Correct 133 ms 13560 KB Output is correct
13 Correct 99 ms 13432 KB Output is correct
14 Correct 99 ms 13304 KB Output is correct
15 Correct 94 ms 12664 KB Output is correct
16 Correct 124 ms 12408 KB Output is correct
17 Correct 11 ms 7168 KB Output is correct
18 Correct 10 ms 7168 KB Output is correct
19 Correct 11 ms 7168 KB Output is correct
20 Correct 11 ms 7168 KB Output is correct
21 Correct 14 ms 7168 KB Output is correct
22 Correct 10 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5248 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5248 KB Output is correct
5 Correct 9 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 10 ms 5248 KB Output is correct
8 Correct 9 ms 5248 KB Output is correct
9 Correct 8 ms 5248 KB Output is correct
10 Correct 8 ms 5248 KB Output is correct
11 Correct 8 ms 5120 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 8 ms 5120 KB Output is correct
14 Correct 9 ms 5120 KB Output is correct
15 Correct 8 ms 5120 KB Output is correct
16 Correct 8 ms 5120 KB Output is correct
17 Correct 8 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 8 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 16248 KB Output is correct
2 Correct 149 ms 16248 KB Output is correct
3 Correct 181 ms 16248 KB Output is correct
4 Correct 157 ms 16376 KB Output is correct
5 Correct 180 ms 16344 KB Output is correct
6 Correct 186 ms 20604 KB Output is correct
7 Correct 184 ms 19448 KB Output is correct
8 Correct 172 ms 18576 KB Output is correct
9 Correct 176 ms 17784 KB Output is correct
10 Correct 160 ms 16248 KB Output is correct
11 Correct 166 ms 16180 KB Output is correct
12 Correct 168 ms 16248 KB Output is correct
13 Correct 171 ms 16312 KB Output is correct
14 Correct 140 ms 15736 KB Output is correct
15 Correct 131 ms 15096 KB Output is correct
16 Correct 99 ms 12872 KB Output is correct
17 Correct 95 ms 16748 KB Output is correct
18 Correct 92 ms 16744 KB Output is correct
19 Correct 89 ms 16632 KB Output is correct
20 Correct 140 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 5248 KB Output is correct
2 Correct 10 ms 5248 KB Output is correct
3 Correct 9 ms 5248 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 8 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Correct 8 ms 5120 KB Output is correct
9 Correct 8 ms 5120 KB Output is correct
10 Correct 9 ms 5120 KB Output is correct
11 Correct 8 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 9 ms 5248 KB Output is correct
14 Correct 8 ms 5248 KB Output is correct
15 Correct 8 ms 5248 KB Output is correct
16 Correct 8 ms 5120 KB Output is correct
17 Correct 8 ms 5248 KB Output is correct
18 Correct 8 ms 5248 KB Output is correct
19 Correct 8 ms 5120 KB Output is correct
20 Correct 8 ms 5120 KB Output is correct
21 Correct 10 ms 5248 KB Output is correct
22 Correct 8 ms 5120 KB Output is correct
23 Correct 8 ms 5248 KB Output is correct
24 Correct 8 ms 5248 KB Output is correct
25 Correct 8 ms 5120 KB Output is correct
26 Correct 9 ms 5120 KB Output is correct
27 Correct 7 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 16520 KB Output is correct
2 Correct 148 ms 16120 KB Output is correct
3 Correct 143 ms 15224 KB Output is correct
4 Correct 130 ms 14328 KB Output is correct
5 Correct 129 ms 13560 KB Output is correct
6 Correct 121 ms 13176 KB Output is correct
7 Correct 129 ms 12920 KB Output is correct
8 Correct 104 ms 12792 KB Output is correct
9 Correct 109 ms 12664 KB Output is correct
10 Correct 103 ms 12664 KB Output is correct
11 Correct 103 ms 12536 KB Output is correct
12 Correct 102 ms 12664 KB Output is correct
13 Correct 117 ms 12640 KB Output is correct
14 Correct 116 ms 14104 KB Output is correct
15 Correct 160 ms 18168 KB Output is correct
16 Correct 254 ms 17656 KB Output is correct
17 Correct 239 ms 18424 KB Output is correct
18 Correct 139 ms 16632 KB Output is correct
19 Correct 141 ms 14332 KB Output is correct
20 Correct 138 ms 14328 KB Output is correct
21 Correct 124 ms 14328 KB Output is correct
22 Correct 137 ms 13816 KB Output is correct
23 Correct 124 ms 13336 KB Output is correct
24 Correct 122 ms 15472 KB Output is correct
25 Correct 121 ms 15732 KB Output is correct
26 Correct 128 ms 14968 KB Output is correct
27 Correct 122 ms 14844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Incorrect 8 ms 5120 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
5 Correct 7 ms 5120 KB Output is correct
6 Correct 8 ms 5120 KB Output is correct
7 Correct 8 ms 5120 KB Output is correct
8 Incorrect 8 ms 5120 KB Output isn't correct
9 Halted 0 ms 0 KB -