Submission #108446

# Submission time Handle Problem Language Result Execution time Memory
108446 2019-04-29T16:10:45 Z PeppaPig Duathlon (APIO18_duathlon) C++14
82 / 100
890 ms 31120 KB
#include <bits/stdc++.h>

#define long long long
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 3e5+5;

int n, m;
int pre[N], low[N], ap[N], id[N];
vector<vector<int> > g(N), bcc;
vector<int> sz;

void tarjan(int u, int p) {
    static int idx = 0;
    static stack<int> S;
    pre[u] = low[u] = ++idx, S.emplace(u);
    int cnt = 0;
    for(int v : g[u]) if(v != p) {
        if(!pre[v]) {
            ++cnt;
            tarjan(v, u);
            low[u] = min(low[u], low[v]);
            if((!p && cnt > 1) || (p && low[v] >= pre[u])) ap[u] = 1;
            if(low[v] >= pre[u]) {
                bcc.emplace_back(vector<int>(1, u));
                while(bcc.back().back() != v) {
                    bcc.back().emplace_back(S.top());
                    S.pop();
                } 
            }
        } else low[u] = min(low[u], pre[v]);
    }
}

bitset<N> idart;

void gen_bct() {
    g.clear();
    g.emplace_back(vector<int>());
    sz.emplace_back(0);
    for(int i = 1; i <= n; i++) if(ap[i]) {
        idart[id[i] = g.size()] = true;
        g.emplace_back(vector<int>());
        sz.emplace_back(1);
    }
    for(vector<int> &cc : bcc) {
        g.emplace_back(vector<int>());
        sz.emplace_back(cc.size());
        for(int v : cc) {
            if(ap[v]) g[id[v]].emplace_back(g.size()-1), g[g.size()-1].emplace_back(id[v]);
            else id[v] = g.size()-1;
        }
    }
}

bitset<N> chk;
int siz[N];
long ans, sum_sz, sum_sz2;

int getsz(int u, int p) { siz[u] = 1; for(int v : g[u]) if(v != p && !chk[v]) siz[u] += getsz(v, u); return siz[u]; }

int find_cen(int u, int p, int all, pii &ret) {
    int mx = all - siz[u];
    for(int v : g[u]) if(v != p && !chk[v])
        mx = max(mx, find_cen(v, u, all, ret));
    ret = min(ret, pii(mx, u));
    return siz[u];
}

int noap_sz(int u) { return idart[u] ? 1 : sz[u] - g[u].size(); } //Non-overlap Size
int noad_sz(int u) { return sz[u] - 2 * (int)!idart[u]; } //Size with no 2 adjacent APs

void dfs(int u, int p, long all, bool fill) {
    if(!fill) ans += 1ll * noap_sz(u) * (sum_sz2 + sum_sz * (all - idart[u])); //Start * (Change another subtree + Change this subtree)
    else {
        sum_sz += noap_sz(u); //Finish
        sum_sz2 += 1ll * (all - idart[u]) * noap_sz(u); //Change and Finish
    }
    for(int v : g[u]) if(v != p && !chk[v]) dfs(v, u, all + noad_sz(v), fill);
}

void proc(int u) {
    getsz(u, u);
    pii ret(siz[u] + 1, -1);
    find_cen(u, u, siz[u], ret);
    chk[u = ret.y] = true;
    
    if(sz[u] > 2) ans += 1ll * (sz[u] - 2) * (noap_sz(u) * (noap_sz(u)-1) / 2ll);
    sum_sz = noap_sz(u);
    sum_sz2 = idart[u] ? 0 : 1ll * noad_sz(u) * noap_sz(u);
    for(int v : g[u]) if(!chk[v]) {
        dfs(v, u, noad_sz(v), 0);
        dfs(v, u, noad_sz(u) + noad_sz(v), 1);
    }
    for(int v : g[u]) if(!chk[v]) proc(v);
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1, a, b; i <= m; i++) {
        scanf("%d %d", &a, &b);
        g[a].emplace_back(b), g[b].emplace_back(a);
    }
    for(int i = 1; i <= n; i++) if(!pre[i]) tarjan(i, 0);
    gen_bct();

    for(int i = 1; i < (int)g.size(); i++) if(!chk[i]) proc(i);
    printf("%lld\n", 2ll * ans);

    return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:103:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:105:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 10 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 10 ms 7456 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 8 ms 7552 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 9 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 11 ms 7424 KB Output is correct
30 Correct 10 ms 7424 KB Output is correct
31 Correct 10 ms 7424 KB Output is correct
32 Correct 10 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 9 ms 7408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 10 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 10 ms 7456 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 8 ms 7552 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 9 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 11 ms 7424 KB Output is correct
30 Correct 10 ms 7424 KB Output is correct
31 Correct 10 ms 7424 KB Output is correct
32 Correct 10 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 9 ms 7408 KB Output is correct
36 Correct 9 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 12 ms 7424 KB Output is correct
39 Correct 10 ms 7384 KB Output is correct
40 Correct 9 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 10 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 11 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 8 ms 7424 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 9 ms 7468 KB Output is correct
50 Correct 10 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 11 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 8 ms 7424 KB Output is correct
55 Correct 9 ms 7424 KB Output is correct
56 Correct 9 ms 7424 KB Output is correct
57 Correct 9 ms 7424 KB Output is correct
58 Correct 9 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7424 KB Output is correct
62 Correct 11 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 11 ms 7424 KB Output is correct
65 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 23420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 8 ms 7552 KB Output is correct
3 Correct 9 ms 7552 KB Output is correct
4 Correct 10 ms 7680 KB Output is correct
5 Correct 11 ms 7680 KB Output is correct
6 Correct 9 ms 7552 KB Output is correct
7 Correct 10 ms 7680 KB Output is correct
8 Correct 9 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 9 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 12 ms 7552 KB Output is correct
14 Correct 8 ms 7552 KB Output is correct
15 Correct 16 ms 7552 KB Output is correct
16 Correct 11 ms 7524 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 9 ms 7552 KB Output is correct
19 Correct 10 ms 7552 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 20464 KB Output is correct
2 Correct 396 ms 20636 KB Output is correct
3 Correct 464 ms 20492 KB Output is correct
4 Correct 490 ms 20516 KB Output is correct
5 Correct 441 ms 20552 KB Output is correct
6 Correct 890 ms 31120 KB Output is correct
7 Correct 781 ms 27220 KB Output is correct
8 Correct 858 ms 26704 KB Output is correct
9 Correct 822 ms 24696 KB Output is correct
10 Correct 368 ms 20616 KB Output is correct
11 Correct 331 ms 20444 KB Output is correct
12 Correct 358 ms 20556 KB Output is correct
13 Correct 326 ms 20392 KB Output is correct
14 Correct 183 ms 19672 KB Output is correct
15 Correct 158 ms 18184 KB Output is correct
16 Correct 92 ms 14764 KB Output is correct
17 Correct 172 ms 19092 KB Output is correct
18 Correct 124 ms 18708 KB Output is correct
19 Correct 116 ms 18580 KB Output is correct
20 Correct 141 ms 18452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7552 KB Output is correct
2 Correct 9 ms 7556 KB Output is correct
3 Correct 10 ms 7596 KB Output is correct
4 Correct 9 ms 7552 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 11 ms 7552 KB Output is correct
7 Correct 9 ms 7552 KB Output is correct
8 Correct 9 ms 7552 KB Output is correct
9 Correct 9 ms 7552 KB Output is correct
10 Correct 13 ms 7424 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7680 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 9 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 10 ms 7524 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 8 ms 7552 KB Output is correct
23 Correct 9 ms 7552 KB Output is correct
24 Correct 9 ms 7552 KB Output is correct
25 Correct 8 ms 7484 KB Output is correct
26 Correct 8 ms 7424 KB Output is correct
27 Correct 9 ms 7440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 464 ms 20404 KB Output is correct
2 Correct 495 ms 20968 KB Output is correct
3 Correct 481 ms 19264 KB Output is correct
4 Correct 339 ms 16684 KB Output is correct
5 Correct 242 ms 14612 KB Output is correct
6 Correct 202 ms 14056 KB Output is correct
7 Correct 218 ms 13716 KB Output is correct
8 Correct 140 ms 13364 KB Output is correct
9 Correct 120 ms 13184 KB Output is correct
10 Correct 151 ms 13292 KB Output is correct
11 Correct 134 ms 12996 KB Output is correct
12 Correct 126 ms 12956 KB Output is correct
13 Correct 118 ms 13020 KB Output is correct
14 Correct 119 ms 15452 KB Output is correct
15 Correct 526 ms 25488 KB Output is correct
16 Correct 560 ms 23544 KB Output is correct
17 Correct 411 ms 24232 KB Output is correct
18 Correct 617 ms 21252 KB Output is correct
19 Correct 378 ms 16788 KB Output is correct
20 Correct 351 ms 16516 KB Output is correct
21 Correct 301 ms 16776 KB Output is correct
22 Correct 233 ms 15472 KB Output is correct
23 Correct 205 ms 14636 KB Output is correct
24 Correct 227 ms 18364 KB Output is correct
25 Correct 232 ms 18544 KB Output is correct
26 Correct 189 ms 17156 KB Output is correct
27 Correct 225 ms 17104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 10 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 10 ms 7456 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 8 ms 7552 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 9 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 11 ms 7424 KB Output is correct
30 Correct 10 ms 7424 KB Output is correct
31 Correct 10 ms 7424 KB Output is correct
32 Correct 10 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 9 ms 7408 KB Output is correct
36 Correct 9 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 12 ms 7424 KB Output is correct
39 Correct 10 ms 7384 KB Output is correct
40 Correct 9 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 10 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 11 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 8 ms 7424 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 9 ms 7468 KB Output is correct
50 Correct 10 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 11 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 8 ms 7424 KB Output is correct
55 Correct 9 ms 7424 KB Output is correct
56 Correct 9 ms 7424 KB Output is correct
57 Correct 9 ms 7424 KB Output is correct
58 Correct 9 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7424 KB Output is correct
62 Correct 11 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 11 ms 7424 KB Output is correct
65 Correct 9 ms 7424 KB Output is correct
66 Correct 8 ms 7424 KB Output is correct
67 Correct 10 ms 7552 KB Output is correct
68 Correct 10 ms 7552 KB Output is correct
69 Correct 10 ms 7552 KB Output is correct
70 Correct 9 ms 7552 KB Output is correct
71 Correct 8 ms 7424 KB Output is correct
72 Correct 11 ms 7424 KB Output is correct
73 Correct 9 ms 7552 KB Output is correct
74 Correct 9 ms 7424 KB Output is correct
75 Correct 10 ms 7424 KB Output is correct
76 Correct 10 ms 7424 KB Output is correct
77 Correct 11 ms 7552 KB Output is correct
78 Correct 8 ms 7424 KB Output is correct
79 Correct 9 ms 7424 KB Output is correct
80 Correct 13 ms 7424 KB Output is correct
81 Correct 10 ms 7424 KB Output is correct
82 Correct 8 ms 7552 KB Output is correct
83 Correct 10 ms 7516 KB Output is correct
84 Correct 9 ms 7552 KB Output is correct
85 Correct 10 ms 7552 KB Output is correct
86 Correct 10 ms 7424 KB Output is correct
87 Correct 10 ms 7552 KB Output is correct
88 Correct 11 ms 7552 KB Output is correct
89 Correct 8 ms 7424 KB Output is correct
90 Correct 8 ms 7552 KB Output is correct
91 Correct 8 ms 7424 KB Output is correct
92 Correct 9 ms 7552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 7 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 10 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 10 ms 7424 KB Output is correct
9 Correct 8 ms 7424 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 9 ms 7424 KB Output is correct
12 Correct 9 ms 7424 KB Output is correct
13 Correct 9 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 10 ms 7424 KB Output is correct
16 Correct 9 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 9 ms 7424 KB Output is correct
19 Correct 9 ms 7424 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 10 ms 7424 KB Output is correct
22 Correct 8 ms 7424 KB Output is correct
23 Correct 10 ms 7456 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 8 ms 7552 KB Output is correct
26 Correct 9 ms 7424 KB Output is correct
27 Correct 9 ms 7424 KB Output is correct
28 Correct 10 ms 7424 KB Output is correct
29 Correct 11 ms 7424 KB Output is correct
30 Correct 10 ms 7424 KB Output is correct
31 Correct 10 ms 7424 KB Output is correct
32 Correct 10 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 9 ms 7408 KB Output is correct
36 Correct 9 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 12 ms 7424 KB Output is correct
39 Correct 10 ms 7384 KB Output is correct
40 Correct 9 ms 7424 KB Output is correct
41 Correct 8 ms 7424 KB Output is correct
42 Correct 10 ms 7424 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 11 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 8 ms 7424 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 9 ms 7468 KB Output is correct
50 Correct 10 ms 7424 KB Output is correct
51 Correct 8 ms 7424 KB Output is correct
52 Correct 11 ms 7424 KB Output is correct
53 Correct 8 ms 7424 KB Output is correct
54 Correct 8 ms 7424 KB Output is correct
55 Correct 9 ms 7424 KB Output is correct
56 Correct 9 ms 7424 KB Output is correct
57 Correct 9 ms 7424 KB Output is correct
58 Correct 9 ms 7424 KB Output is correct
59 Correct 9 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7424 KB Output is correct
62 Correct 11 ms 7424 KB Output is correct
63 Correct 9 ms 7424 KB Output is correct
64 Correct 11 ms 7424 KB Output is correct
65 Correct 9 ms 7424 KB Output is correct
66 Incorrect 152 ms 23420 KB Output isn't correct
67 Halted 0 ms 0 KB -