답안 #108442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108442 2019-04-29T15:28:07 Z PeppaPig 철인 이종 경기 (APIO18_duathlon) C++14
49 / 100
1000 ms 18672 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 = 1e5+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 - sz[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));
}

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(sz[u] + 1, -1);
    find_cen(u, u, sz[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 find_cen(int, int, int, std::pair<int, int>&)':
count_triplets.cpp:71:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:102: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:104: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 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2764 KB Output is correct
8 Correct 5 ms 2688 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 8 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 5 ms 2688 KB Output is correct
30 Correct 5 ms 2688 KB Output is correct
31 Correct 5 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 5 ms 2688 KB Output is correct
34 Correct 5 ms 2688 KB Output is correct
35 Correct 5 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2764 KB Output is correct
8 Correct 5 ms 2688 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 8 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 5 ms 2688 KB Output is correct
30 Correct 5 ms 2688 KB Output is correct
31 Correct 5 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 5 ms 2688 KB Output is correct
34 Correct 5 ms 2688 KB Output is correct
35 Correct 5 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 26 ms 2688 KB Output is correct
39 Correct 5 ms 2688 KB Output is correct
40 Correct 7 ms 2688 KB Output is correct
41 Correct 5 ms 2688 KB Output is correct
42 Correct 5 ms 2688 KB Output is correct
43 Correct 5 ms 2688 KB Output is correct
44 Correct 5 ms 2688 KB Output is correct
45 Correct 5 ms 2688 KB Output is correct
46 Correct 5 ms 2688 KB Output is correct
47 Correct 5 ms 2688 KB Output is correct
48 Correct 5 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2660 KB Output is correct
51 Correct 5 ms 2688 KB Output is correct
52 Correct 5 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 5 ms 2688 KB Output is correct
55 Correct 5 ms 2688 KB Output is correct
56 Correct 4 ms 2688 KB Output is correct
57 Correct 4 ms 2688 KB Output is correct
58 Correct 4 ms 2688 KB Output is correct
59 Correct 5 ms 2680 KB Output is correct
60 Correct 5 ms 2688 KB Output is correct
61 Correct 4 ms 2688 KB Output is correct
62 Correct 5 ms 2688 KB Output is correct
63 Correct 2 ms 2688 KB Output is correct
64 Correct 4 ms 2688 KB Output is correct
65 Correct 5 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 122 ms 18672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 2936 KB Output is correct
2 Correct 48 ms 2944 KB Output is correct
3 Correct 52 ms 2936 KB Output is correct
4 Correct 64 ms 3072 KB Output is correct
5 Correct 66 ms 3064 KB Output is correct
6 Correct 62 ms 3000 KB Output is correct
7 Correct 54 ms 2944 KB Output is correct
8 Correct 57 ms 2944 KB Output is correct
9 Correct 67 ms 2944 KB Output is correct
10 Correct 52 ms 2936 KB Output is correct
11 Correct 39 ms 2936 KB Output is correct
12 Correct 31 ms 2936 KB Output is correct
13 Correct 12 ms 2816 KB Output is correct
14 Correct 5 ms 2816 KB Output is correct
15 Correct 6 ms 2816 KB Output is correct
16 Correct 5 ms 2816 KB Output is correct
17 Correct 29 ms 2944 KB Output is correct
18 Correct 28 ms 2944 KB Output is correct
19 Correct 31 ms 2944 KB Output is correct
20 Correct 45 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1050 ms 16880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 2936 KB Output is correct
2 Correct 56 ms 2944 KB Output is correct
3 Correct 19 ms 2916 KB Output is correct
4 Correct 12 ms 2816 KB Output is correct
5 Correct 8 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 5 ms 2816 KB Output is correct
8 Correct 6 ms 2816 KB Output is correct
9 Correct 6 ms 2816 KB Output is correct
10 Correct 5 ms 2816 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 16 ms 2944 KB Output is correct
13 Correct 17 ms 2944 KB Output is correct
14 Correct 10 ms 2944 KB Output is correct
15 Correct 10 ms 2816 KB Output is correct
16 Correct 10 ms 2816 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 7 ms 2816 KB Output is correct
19 Correct 5 ms 2816 KB Output is correct
20 Correct 6 ms 2816 KB Output is correct
21 Correct 36 ms 2936 KB Output is correct
22 Correct 30 ms 2936 KB Output is correct
23 Correct 21 ms 2816 KB Output is correct
24 Correct 14 ms 2816 KB Output is correct
25 Correct 4 ms 2816 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 16848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2764 KB Output is correct
8 Correct 5 ms 2688 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 8 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 5 ms 2688 KB Output is correct
30 Correct 5 ms 2688 KB Output is correct
31 Correct 5 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 5 ms 2688 KB Output is correct
34 Correct 5 ms 2688 KB Output is correct
35 Correct 5 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 26 ms 2688 KB Output is correct
39 Correct 5 ms 2688 KB Output is correct
40 Correct 7 ms 2688 KB Output is correct
41 Correct 5 ms 2688 KB Output is correct
42 Correct 5 ms 2688 KB Output is correct
43 Correct 5 ms 2688 KB Output is correct
44 Correct 5 ms 2688 KB Output is correct
45 Correct 5 ms 2688 KB Output is correct
46 Correct 5 ms 2688 KB Output is correct
47 Correct 5 ms 2688 KB Output is correct
48 Correct 5 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2660 KB Output is correct
51 Correct 5 ms 2688 KB Output is correct
52 Correct 5 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 5 ms 2688 KB Output is correct
55 Correct 5 ms 2688 KB Output is correct
56 Correct 4 ms 2688 KB Output is correct
57 Correct 4 ms 2688 KB Output is correct
58 Correct 4 ms 2688 KB Output is correct
59 Correct 5 ms 2680 KB Output is correct
60 Correct 5 ms 2688 KB Output is correct
61 Correct 4 ms 2688 KB Output is correct
62 Correct 5 ms 2688 KB Output is correct
63 Correct 2 ms 2688 KB Output is correct
64 Correct 4 ms 2688 KB Output is correct
65 Correct 5 ms 2688 KB Output is correct
66 Correct 4 ms 2688 KB Output is correct
67 Correct 6 ms 2816 KB Output is correct
68 Correct 13 ms 2816 KB Output is correct
69 Correct 19 ms 2816 KB Output is correct
70 Correct 6 ms 2816 KB Output is correct
71 Correct 5 ms 2816 KB Output is correct
72 Correct 7 ms 2816 KB Output is correct
73 Correct 5 ms 2816 KB Output is correct
74 Correct 5 ms 2816 KB Output is correct
75 Correct 6 ms 2816 KB Output is correct
76 Correct 4 ms 2688 KB Output is correct
77 Correct 16 ms 2816 KB Output is correct
78 Correct 10 ms 2816 KB Output is correct
79 Correct 6 ms 2816 KB Output is correct
80 Correct 5 ms 2816 KB Output is correct
81 Correct 5 ms 2816 KB Output is correct
82 Correct 5 ms 2816 KB Output is correct
83 Correct 6 ms 2816 KB Output is correct
84 Correct 10 ms 2816 KB Output is correct
85 Correct 14 ms 2816 KB Output is correct
86 Correct 9 ms 2816 KB Output is correct
87 Correct 7 ms 2816 KB Output is correct
88 Correct 7 ms 2816 KB Output is correct
89 Correct 6 ms 2816 KB Output is correct
90 Correct 6 ms 2816 KB Output is correct
91 Correct 9 ms 2816 KB Output is correct
92 Correct 9 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 5 ms 2688 KB Output is correct
5 Correct 4 ms 2688 KB Output is correct
6 Correct 5 ms 2688 KB Output is correct
7 Correct 5 ms 2764 KB Output is correct
8 Correct 5 ms 2688 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2688 KB Output is correct
11 Correct 4 ms 2688 KB Output is correct
12 Correct 5 ms 2688 KB Output is correct
13 Correct 3 ms 2688 KB Output is correct
14 Correct 4 ms 2688 KB Output is correct
15 Correct 4 ms 2688 KB Output is correct
16 Correct 5 ms 2688 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 8 ms 2688 KB Output is correct
19 Correct 5 ms 2688 KB Output is correct
20 Correct 4 ms 2688 KB Output is correct
21 Correct 4 ms 2688 KB Output is correct
22 Correct 4 ms 2688 KB Output is correct
23 Correct 3 ms 2688 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 5 ms 2688 KB Output is correct
26 Correct 5 ms 2688 KB Output is correct
27 Correct 4 ms 2688 KB Output is correct
28 Correct 4 ms 2688 KB Output is correct
29 Correct 5 ms 2688 KB Output is correct
30 Correct 5 ms 2688 KB Output is correct
31 Correct 5 ms 2688 KB Output is correct
32 Correct 4 ms 2688 KB Output is correct
33 Correct 5 ms 2688 KB Output is correct
34 Correct 5 ms 2688 KB Output is correct
35 Correct 5 ms 2688 KB Output is correct
36 Correct 4 ms 2688 KB Output is correct
37 Correct 4 ms 2688 KB Output is correct
38 Correct 26 ms 2688 KB Output is correct
39 Correct 5 ms 2688 KB Output is correct
40 Correct 7 ms 2688 KB Output is correct
41 Correct 5 ms 2688 KB Output is correct
42 Correct 5 ms 2688 KB Output is correct
43 Correct 5 ms 2688 KB Output is correct
44 Correct 5 ms 2688 KB Output is correct
45 Correct 5 ms 2688 KB Output is correct
46 Correct 5 ms 2688 KB Output is correct
47 Correct 5 ms 2688 KB Output is correct
48 Correct 5 ms 2688 KB Output is correct
49 Correct 4 ms 2688 KB Output is correct
50 Correct 4 ms 2660 KB Output is correct
51 Correct 5 ms 2688 KB Output is correct
52 Correct 5 ms 2688 KB Output is correct
53 Correct 4 ms 2688 KB Output is correct
54 Correct 5 ms 2688 KB Output is correct
55 Correct 5 ms 2688 KB Output is correct
56 Correct 4 ms 2688 KB Output is correct
57 Correct 4 ms 2688 KB Output is correct
58 Correct 4 ms 2688 KB Output is correct
59 Correct 5 ms 2680 KB Output is correct
60 Correct 5 ms 2688 KB Output is correct
61 Correct 4 ms 2688 KB Output is correct
62 Correct 5 ms 2688 KB Output is correct
63 Correct 2 ms 2688 KB Output is correct
64 Correct 4 ms 2688 KB Output is correct
65 Correct 5 ms 2688 KB Output is correct
66 Incorrect 122 ms 18672 KB Output isn't correct
67 Halted 0 ms 0 KB -