답안 #108445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108445 2019-04-29T16:02:05 Z PeppaPig 철인 이종 경기 (APIO18_duathlon) C++14
82 / 100
799 ms 31064 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 += 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 += (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 += (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);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 10 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7416 KB Output is correct
7 Correct 11 ms 7452 KB Output is correct
8 Correct 9 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 10 ms 7424 KB Output is correct
12 Correct 49 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 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 9 ms 7424 KB Output is correct
22 Correct 9 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 10 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 9 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7448 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 10 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7416 KB Output is correct
7 Correct 11 ms 7452 KB Output is correct
8 Correct 9 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 10 ms 7424 KB Output is correct
12 Correct 49 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 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 9 ms 7424 KB Output is correct
22 Correct 9 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 10 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 9 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7448 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 10 ms 7424 KB Output is correct
41 Correct 24 ms 7424 KB Output is correct
42 Correct 11 ms 7436 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 9 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7552 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 10 ms 7424 KB Output is correct
52 Correct 9 ms 7424 KB Output is correct
53 Correct 11 ms 7424 KB Output is correct
54 Correct 10 ms 7424 KB Output is correct
55 Correct 10 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 10 ms 7424 KB Output is correct
59 Correct 16 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7488 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 8 ms 7424 KB Output is correct
64 Correct 9 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 157 ms 23452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 7552 KB Output is correct
2 Correct 9 ms 7552 KB Output is correct
3 Correct 10 ms 7552 KB Output is correct
4 Correct 11 ms 7680 KB Output is correct
5 Correct 13 ms 7652 KB Output is correct
6 Correct 10 ms 7680 KB Output is correct
7 Correct 11 ms 7680 KB Output is correct
8 Correct 13 ms 7680 KB Output is correct
9 Correct 11 ms 7552 KB Output is correct
10 Correct 9 ms 7552 KB Output is correct
11 Correct 12 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 9 ms 7552 KB Output is correct
15 Correct 9 ms 7552 KB Output is correct
16 Correct 8 ms 7424 KB Output is correct
17 Correct 8 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 8 ms 7552 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 20492 KB Output is correct
2 Correct 350 ms 20528 KB Output is correct
3 Correct 449 ms 20680 KB Output is correct
4 Correct 373 ms 20600 KB Output is correct
5 Correct 350 ms 20524 KB Output is correct
6 Correct 749 ms 31064 KB Output is correct
7 Correct 717 ms 27196 KB Output is correct
8 Correct 799 ms 26536 KB Output is correct
9 Correct 787 ms 24616 KB Output is correct
10 Correct 429 ms 20520 KB Output is correct
11 Correct 455 ms 20528 KB Output is correct
12 Correct 358 ms 20520 KB Output is correct
13 Correct 370 ms 20508 KB Output is correct
14 Correct 238 ms 19612 KB Output is correct
15 Correct 196 ms 18212 KB Output is correct
16 Correct 93 ms 14864 KB Output is correct
17 Correct 117 ms 19008 KB Output is correct
18 Correct 178 ms 18580 KB Output is correct
19 Correct 140 ms 18684 KB Output is correct
20 Correct 136 ms 18580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 7552 KB Output is correct
2 Correct 11 ms 7552 KB Output is correct
3 Correct 12 ms 7552 KB Output is correct
4 Correct 11 ms 7552 KB Output is correct
5 Correct 10 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 10 ms 7424 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7424 KB Output is correct
12 Correct 10 ms 7680 KB Output is correct
13 Correct 11 ms 7580 KB Output is correct
14 Correct 10 ms 7552 KB Output is correct
15 Correct 11 ms 7552 KB Output is correct
16 Correct 10 ms 7552 KB Output is correct
17 Correct 7 ms 7424 KB Output is correct
18 Correct 11 ms 7552 KB Output is correct
19 Correct 11 ms 7424 KB Output is correct
20 Correct 10 ms 7556 KB Output is correct
21 Correct 11 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 9 ms 7552 KB Output is correct
24 Correct 11 ms 7552 KB Output is correct
25 Correct 10 ms 7484 KB Output is correct
26 Correct 8 ms 7424 KB Output is correct
27 Correct 8 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 445 ms 20548 KB Output is correct
2 Correct 330 ms 20904 KB Output is correct
3 Correct 435 ms 19096 KB Output is correct
4 Correct 353 ms 16704 KB Output is correct
5 Correct 285 ms 14656 KB Output is correct
6 Correct 192 ms 14000 KB Output is correct
7 Correct 192 ms 13744 KB Output is correct
8 Correct 167 ms 13384 KB Output is correct
9 Correct 174 ms 13236 KB Output is correct
10 Correct 133 ms 13048 KB Output is correct
11 Correct 122 ms 12972 KB Output is correct
12 Correct 127 ms 13064 KB Output is correct
13 Correct 125 ms 13092 KB Output is correct
14 Correct 134 ms 15480 KB Output is correct
15 Correct 639 ms 25652 KB Output is correct
16 Correct 551 ms 23428 KB Output is correct
17 Correct 577 ms 24184 KB Output is correct
18 Correct 456 ms 21268 KB Output is correct
19 Correct 383 ms 16604 KB Output is correct
20 Correct 328 ms 16556 KB Output is correct
21 Correct 257 ms 16556 KB Output is correct
22 Correct 148 ms 15276 KB Output is correct
23 Correct 150 ms 14592 KB Output is correct
24 Correct 284 ms 18388 KB Output is correct
25 Correct 289 ms 18656 KB Output is correct
26 Correct 235 ms 17036 KB Output is correct
27 Correct 162 ms 17072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 10 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7416 KB Output is correct
7 Correct 11 ms 7452 KB Output is correct
8 Correct 9 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 10 ms 7424 KB Output is correct
12 Correct 49 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 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 9 ms 7424 KB Output is correct
22 Correct 9 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 10 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 9 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7448 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 10 ms 7424 KB Output is correct
41 Correct 24 ms 7424 KB Output is correct
42 Correct 11 ms 7436 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 9 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7552 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 10 ms 7424 KB Output is correct
52 Correct 9 ms 7424 KB Output is correct
53 Correct 11 ms 7424 KB Output is correct
54 Correct 10 ms 7424 KB Output is correct
55 Correct 10 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 10 ms 7424 KB Output is correct
59 Correct 16 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7488 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 8 ms 7424 KB Output is correct
64 Correct 9 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
66 Correct 11 ms 7424 KB Output is correct
67 Correct 11 ms 7424 KB Output is correct
68 Correct 11 ms 7552 KB Output is correct
69 Correct 11 ms 7552 KB Output is correct
70 Correct 11 ms 7552 KB Output is correct
71 Correct 9 ms 7552 KB Output is correct
72 Correct 10 ms 7524 KB Output is correct
73 Correct 9 ms 7552 KB Output is correct
74 Correct 8 ms 7552 KB Output is correct
75 Correct 9 ms 7552 KB Output is correct
76 Correct 8 ms 7424 KB Output is correct
77 Correct 10 ms 7552 KB Output is correct
78 Correct 10 ms 7524 KB Output is correct
79 Correct 10 ms 7424 KB Output is correct
80 Correct 9 ms 7552 KB Output is correct
81 Correct 9 ms 7552 KB Output is correct
82 Correct 8 ms 7552 KB Output is correct
83 Correct 9 ms 7552 KB Output is correct
84 Correct 11 ms 7596 KB Output is correct
85 Correct 9 ms 7552 KB Output is correct
86 Correct 9 ms 7424 KB Output is correct
87 Correct 9 ms 7424 KB Output is correct
88 Correct 10 ms 7552 KB Output is correct
89 Correct 9 ms 7424 KB Output is correct
90 Correct 9 ms 7552 KB Output is correct
91 Correct 9 ms 7552 KB Output is correct
92 Correct 9 ms 7524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Correct 9 ms 7424 KB Output is correct
4 Correct 10 ms 7424 KB Output is correct
5 Correct 9 ms 7424 KB Output is correct
6 Correct 10 ms 7416 KB Output is correct
7 Correct 11 ms 7452 KB Output is correct
8 Correct 9 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 10 ms 7424 KB Output is correct
12 Correct 49 ms 7424 KB Output is correct
13 Correct 10 ms 7424 KB Output is correct
14 Correct 10 ms 7424 KB Output is correct
15 Correct 11 ms 7424 KB Output is correct
16 Correct 10 ms 7424 KB Output is correct
17 Correct 9 ms 7424 KB Output is correct
18 Correct 10 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 9 ms 7424 KB Output is correct
22 Correct 9 ms 7424 KB Output is correct
23 Correct 10 ms 7424 KB Output is correct
24 Correct 8 ms 7424 KB Output is correct
25 Correct 9 ms 7424 KB Output is correct
26 Correct 10 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 9 ms 7424 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
31 Correct 8 ms 7424 KB Output is correct
32 Correct 8 ms 7424 KB Output is correct
33 Correct 10 ms 7424 KB Output is correct
34 Correct 9 ms 7448 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 8 ms 7424 KB Output is correct
37 Correct 10 ms 7424 KB Output is correct
38 Correct 8 ms 7424 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 10 ms 7424 KB Output is correct
41 Correct 24 ms 7424 KB Output is correct
42 Correct 11 ms 7436 KB Output is correct
43 Correct 9 ms 7424 KB Output is correct
44 Correct 9 ms 7424 KB Output is correct
45 Correct 9 ms 7424 KB Output is correct
46 Correct 9 ms 7552 KB Output is correct
47 Correct 9 ms 7424 KB Output is correct
48 Correct 9 ms 7424 KB Output is correct
49 Correct 8 ms 7424 KB Output is correct
50 Correct 8 ms 7424 KB Output is correct
51 Correct 10 ms 7424 KB Output is correct
52 Correct 9 ms 7424 KB Output is correct
53 Correct 11 ms 7424 KB Output is correct
54 Correct 10 ms 7424 KB Output is correct
55 Correct 10 ms 7424 KB Output is correct
56 Correct 8 ms 7424 KB Output is correct
57 Correct 8 ms 7424 KB Output is correct
58 Correct 10 ms 7424 KB Output is correct
59 Correct 16 ms 7424 KB Output is correct
60 Correct 10 ms 7424 KB Output is correct
61 Correct 10 ms 7488 KB Output is correct
62 Correct 9 ms 7424 KB Output is correct
63 Correct 8 ms 7424 KB Output is correct
64 Correct 9 ms 7424 KB Output is correct
65 Correct 8 ms 7424 KB Output is correct
66 Incorrect 157 ms 23452 KB Output isn't correct
67 Halted 0 ms 0 KB -