답안 #108444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108444 2019-04-29T15:49:20 Z PeppaPig 철인 이종 경기 (APIO18_duathlon) C++14
82 / 100
779 ms 29904 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 = 2e5+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 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 6 ms 4864 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 5 ms 4992 KB Output is correct
19 Correct 6 ms 5096 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 6 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 7 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 6 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5120 KB Output is correct
33 Correct 7 ms 5056 KB Output is correct
34 Correct 7 ms 5120 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 6 ms 4864 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 5 ms 4992 KB Output is correct
19 Correct 6 ms 5096 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 6 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 7 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 6 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5120 KB Output is correct
33 Correct 7 ms 5056 KB Output is correct
34 Correct 7 ms 5120 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 5 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 7 ms 5120 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 6 ms 5092 KB Output is correct
44 Correct 7 ms 4992 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 8 ms 5120 KB Output is correct
47 Correct 7 ms 5120 KB Output is correct
48 Correct 7 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 6 ms 4992 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 7 ms 5120 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 7 ms 4992 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 5120 KB Output is correct
58 Correct 5 ms 4992 KB Output is correct
59 Correct 6 ms 4992 KB Output is correct
60 Correct 6 ms 5120 KB Output is correct
61 Correct 8 ms 4992 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 128 ms 21048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5220 KB Output is correct
2 Correct 9 ms 5248 KB Output is correct
3 Correct 9 ms 5120 KB Output is correct
4 Correct 9 ms 5376 KB Output is correct
5 Correct 7 ms 5248 KB Output is correct
6 Correct 8 ms 5248 KB Output is correct
7 Correct 8 ms 5248 KB Output is correct
8 Correct 8 ms 5276 KB Output is correct
9 Correct 9 ms 5248 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 9 ms 5248 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 6 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 5120 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 380 ms 18208 KB Output is correct
2 Correct 358 ms 19292 KB Output is correct
3 Correct 329 ms 19364 KB Output is correct
4 Correct 348 ms 19452 KB Output is correct
5 Correct 369 ms 19376 KB Output is correct
6 Correct 713 ms 29904 KB Output is correct
7 Correct 575 ms 26072 KB Output is correct
8 Correct 585 ms 25512 KB Output is correct
9 Correct 708 ms 23460 KB Output is correct
10 Correct 377 ms 19472 KB Output is correct
11 Correct 401 ms 19496 KB Output is correct
12 Correct 293 ms 19384 KB Output is correct
13 Correct 332 ms 19468 KB Output is correct
14 Correct 176 ms 18284 KB Output is correct
15 Correct 160 ms 16832 KB Output is correct
16 Correct 90 ms 13120 KB Output is correct
17 Correct 145 ms 17900 KB Output is correct
18 Correct 152 ms 17508 KB Output is correct
19 Correct 133 ms 17524 KB Output is correct
20 Correct 165 ms 17368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 8 ms 5248 KB Output is correct
3 Correct 9 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 7 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 9 ms 5120 KB Output is correct
10 Correct 7 ms 5120 KB Output is correct
11 Correct 7 ms 5120 KB Output is correct
12 Correct 9 ms 5248 KB Output is correct
13 Correct 10 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 7 ms 5120 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 9 ms 5120 KB Output is correct
19 Correct 7 ms 5120 KB Output is correct
20 Correct 9 ms 5120 KB Output is correct
21 Correct 7 ms 5120 KB Output is correct
22 Correct 7 ms 5120 KB Output is correct
23 Correct 9 ms 5376 KB Output is correct
24 Correct 8 ms 5120 KB Output is correct
25 Correct 6 ms 5120 KB Output is correct
26 Correct 8 ms 5156 KB Output is correct
27 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 354 ms 18284 KB Output is correct
2 Correct 355 ms 19752 KB Output is correct
3 Correct 341 ms 18200 KB Output is correct
4 Correct 294 ms 15788 KB Output is correct
5 Correct 213 ms 13648 KB Output is correct
6 Correct 175 ms 12976 KB Output is correct
7 Correct 179 ms 12720 KB Output is correct
8 Correct 160 ms 12340 KB Output is correct
9 Correct 125 ms 12212 KB Output is correct
10 Correct 135 ms 12044 KB Output is correct
11 Correct 119 ms 11940 KB Output is correct
12 Correct 112 ms 11932 KB Output is correct
13 Correct 113 ms 11896 KB Output is correct
14 Correct 126 ms 14328 KB Output is correct
15 Correct 655 ms 24740 KB Output is correct
16 Correct 779 ms 22484 KB Output is correct
17 Correct 684 ms 23284 KB Output is correct
18 Correct 564 ms 20376 KB Output is correct
19 Correct 337 ms 15788 KB Output is correct
20 Correct 278 ms 15692 KB Output is correct
21 Correct 310 ms 15788 KB Output is correct
22 Correct 184 ms 14380 KB Output is correct
23 Correct 145 ms 13484 KB Output is correct
24 Correct 266 ms 17500 KB Output is correct
25 Correct 234 ms 17636 KB Output is correct
26 Correct 212 ms 16260 KB Output is correct
27 Correct 218 ms 16172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 6 ms 4864 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 5 ms 4992 KB Output is correct
19 Correct 6 ms 5096 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 6 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 7 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 6 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5120 KB Output is correct
33 Correct 7 ms 5056 KB Output is correct
34 Correct 7 ms 5120 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 5 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 7 ms 5120 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 6 ms 5092 KB Output is correct
44 Correct 7 ms 4992 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 8 ms 5120 KB Output is correct
47 Correct 7 ms 5120 KB Output is correct
48 Correct 7 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 6 ms 4992 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 7 ms 5120 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 7 ms 4992 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 5120 KB Output is correct
58 Correct 5 ms 4992 KB Output is correct
59 Correct 6 ms 4992 KB Output is correct
60 Correct 6 ms 5120 KB Output is correct
61 Correct 8 ms 4992 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 7 ms 5120 KB Output is correct
66 Correct 6 ms 5120 KB Output is correct
67 Correct 6 ms 5120 KB Output is correct
68 Correct 6 ms 5120 KB Output is correct
69 Correct 6 ms 5120 KB Output is correct
70 Correct 7 ms 5248 KB Output is correct
71 Correct 7 ms 5120 KB Output is correct
72 Correct 7 ms 5120 KB Output is correct
73 Correct 7 ms 5120 KB Output is correct
74 Correct 7 ms 5120 KB Output is correct
75 Correct 8 ms 5120 KB Output is correct
76 Correct 5 ms 4992 KB Output is correct
77 Correct 8 ms 5120 KB Output is correct
78 Correct 8 ms 5120 KB Output is correct
79 Correct 7 ms 5120 KB Output is correct
80 Correct 7 ms 5120 KB Output is correct
81 Correct 7 ms 5120 KB Output is correct
82 Correct 6 ms 5248 KB Output is correct
83 Correct 6 ms 5248 KB Output is correct
84 Correct 8 ms 5120 KB Output is correct
85 Correct 14 ms 5120 KB Output is correct
86 Correct 8 ms 5248 KB Output is correct
87 Correct 7 ms 5120 KB Output is correct
88 Correct 7 ms 5120 KB Output is correct
89 Correct 7 ms 5120 KB Output is correct
90 Correct 8 ms 5120 KB Output is correct
91 Correct 7 ms 5120 KB Output is correct
92 Correct 7 ms 5120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 6 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 6 ms 4864 KB Output is correct
5 Correct 5 ms 4992 KB Output is correct
6 Correct 6 ms 4992 KB Output is correct
7 Correct 5 ms 4992 KB Output is correct
8 Correct 6 ms 5120 KB Output is correct
9 Correct 6 ms 5120 KB Output is correct
10 Correct 7 ms 4992 KB Output is correct
11 Correct 6 ms 4992 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 7 ms 5120 KB Output is correct
14 Correct 7 ms 5120 KB Output is correct
15 Correct 6 ms 5120 KB Output is correct
16 Correct 5 ms 5120 KB Output is correct
17 Correct 6 ms 4992 KB Output is correct
18 Correct 5 ms 4992 KB Output is correct
19 Correct 6 ms 5096 KB Output is correct
20 Correct 6 ms 4992 KB Output is correct
21 Correct 6 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 6 ms 5120 KB Output is correct
24 Correct 7 ms 5120 KB Output is correct
25 Correct 6 ms 4992 KB Output is correct
26 Correct 6 ms 5120 KB Output is correct
27 Correct 6 ms 5120 KB Output is correct
28 Correct 7 ms 5120 KB Output is correct
29 Correct 8 ms 5120 KB Output is correct
30 Correct 6 ms 4992 KB Output is correct
31 Correct 7 ms 5120 KB Output is correct
32 Correct 7 ms 5120 KB Output is correct
33 Correct 7 ms 5056 KB Output is correct
34 Correct 7 ms 5120 KB Output is correct
35 Correct 7 ms 5164 KB Output is correct
36 Correct 7 ms 5120 KB Output is correct
37 Correct 5 ms 4992 KB Output is correct
38 Correct 8 ms 5120 KB Output is correct
39 Correct 6 ms 5120 KB Output is correct
40 Correct 7 ms 5120 KB Output is correct
41 Correct 7 ms 5120 KB Output is correct
42 Correct 7 ms 5120 KB Output is correct
43 Correct 6 ms 5092 KB Output is correct
44 Correct 7 ms 4992 KB Output is correct
45 Correct 6 ms 5120 KB Output is correct
46 Correct 8 ms 5120 KB Output is correct
47 Correct 7 ms 5120 KB Output is correct
48 Correct 7 ms 5120 KB Output is correct
49 Correct 7 ms 5120 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 6 ms 4992 KB Output is correct
52 Correct 6 ms 5120 KB Output is correct
53 Correct 7 ms 5120 KB Output is correct
54 Correct 7 ms 5120 KB Output is correct
55 Correct 7 ms 4992 KB Output is correct
56 Correct 7 ms 5120 KB Output is correct
57 Correct 6 ms 5120 KB Output is correct
58 Correct 5 ms 4992 KB Output is correct
59 Correct 6 ms 4992 KB Output is correct
60 Correct 6 ms 5120 KB Output is correct
61 Correct 8 ms 4992 KB Output is correct
62 Correct 10 ms 5120 KB Output is correct
63 Correct 7 ms 5120 KB Output is correct
64 Correct 8 ms 5120 KB Output is correct
65 Correct 7 ms 5120 KB Output is correct
66 Incorrect 128 ms 21048 KB Output isn't correct
67 Halted 0 ms 0 KB -