Submission #651515

# Submission time Handle Problem Language Result Execution time Memory
651515 2022-10-19T07:10:15 Z dooompy Cat in a tree (BOI17_catinatree) C++17
100 / 100
204 ms 19488 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

vector<pi> v;
vector<int> gph[200005];
int n, d, dep[200005], par[200005], val[200005];
int din[200005], dout[200005], piv;

struct seg{
    int tree[530000], lim;
    void init(){
        memset(tree, 0x3f, sizeof(tree));
        for(lim = 1; lim <= n; lim <<= 1);
    }
    int query(int x){
        x += lim;
        int ret = 1e9;
        while(x){
            ret = min(ret, tree[x]);
            x >>= 1;
        }
        return ret;
    }
    void update(int s, int e, int x){
        s += lim;
        e += lim;
        while(s < e){
            if(s%2 == 1) tree[s] = min(tree[s], x);
            if(e%2 == 0) tree[e] = min(tree[e], x);
            s = (s+1)/2;
            e = (e-1)/2;
        }
        if(s == e) tree[s] = min(tree[s], x);
    }
}seg;

void dfs(int x){
    din[x] = piv++;
    for(auto &i : gph[x]) dfs(i);
    dout[x] = piv;
}

int main(){
    memset(val, 0x3f, sizeof(val));
    scanf("%d %d",&n,&d);
    v.push_back(pi(0, 0));
    par[0] = -1;
    for(int i=1; i<n; i++){
        scanf("%d",&par[i]);
        gph[par[i]].push_back(i);
        dep[i] = dep[par[i]] + 1;
        v.push_back(pi(dep[i], i));
    }
    dfs(0);
    seg.init();
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    int cnt = 0;
    for(auto &i : v){
        if(seg.query(din[i.second]) <= d - 1 - dep[i.second]) continue;
        for(int j=i.second; j!=-1; j=par[j]){
            seg.update(din[j], dout[j]-1, dep[i.second] - 2 * dep[j]);
        }
        cnt++;
    }
    cout << cnt << endl;
}

Compilation message

catinatree.cpp: In function 'int main()':
catinatree.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%d %d",&n,&d);
      |     ~~~~~^~~~~~~~~~~~~~~
catinatree.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         scanf("%d",&par[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7844 KB Output is correct
2 Correct 5 ms 7844 KB Output is correct
3 Correct 4 ms 7764 KB Output is correct
4 Correct 4 ms 7848 KB Output is correct
5 Correct 4 ms 7764 KB Output is correct
6 Correct 5 ms 7764 KB Output is correct
7 Correct 4 ms 7840 KB Output is correct
8 Correct 4 ms 7764 KB Output is correct
9 Correct 4 ms 7844 KB Output is correct
10 Correct 5 ms 7764 KB Output is correct
11 Correct 5 ms 7844 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 5 ms 7764 KB Output is correct
14 Correct 5 ms 7764 KB Output is correct
15 Correct 4 ms 7844 KB Output is correct
16 Correct 5 ms 7840 KB Output is correct
17 Correct 5 ms 7844 KB Output is correct
18 Correct 5 ms 7764 KB Output is correct
19 Correct 5 ms 7864 KB Output is correct
20 Correct 4 ms 7840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7844 KB Output is correct
2 Correct 5 ms 7844 KB Output is correct
3 Correct 4 ms 7764 KB Output is correct
4 Correct 4 ms 7848 KB Output is correct
5 Correct 4 ms 7764 KB Output is correct
6 Correct 5 ms 7764 KB Output is correct
7 Correct 4 ms 7840 KB Output is correct
8 Correct 4 ms 7764 KB Output is correct
9 Correct 4 ms 7844 KB Output is correct
10 Correct 5 ms 7764 KB Output is correct
11 Correct 5 ms 7844 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 5 ms 7764 KB Output is correct
14 Correct 5 ms 7764 KB Output is correct
15 Correct 4 ms 7844 KB Output is correct
16 Correct 5 ms 7840 KB Output is correct
17 Correct 5 ms 7844 KB Output is correct
18 Correct 5 ms 7764 KB Output is correct
19 Correct 5 ms 7864 KB Output is correct
20 Correct 4 ms 7840 KB Output is correct
21 Correct 5 ms 7976 KB Output is correct
22 Correct 5 ms 7892 KB Output is correct
23 Correct 5 ms 7892 KB Output is correct
24 Correct 6 ms 7884 KB Output is correct
25 Correct 6 ms 7892 KB Output is correct
26 Correct 5 ms 7840 KB Output is correct
27 Correct 5 ms 7892 KB Output is correct
28 Correct 5 ms 7892 KB Output is correct
29 Correct 5 ms 7892 KB Output is correct
30 Correct 5 ms 7844 KB Output is correct
31 Correct 5 ms 7892 KB Output is correct
32 Correct 5 ms 7840 KB Output is correct
33 Correct 5 ms 7892 KB Output is correct
34 Correct 6 ms 7892 KB Output is correct
35 Correct 5 ms 7892 KB Output is correct
36 Correct 5 ms 7892 KB Output is correct
37 Correct 5 ms 7892 KB Output is correct
38 Correct 5 ms 7844 KB Output is correct
39 Correct 5 ms 7892 KB Output is correct
40 Correct 14 ms 7996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7844 KB Output is correct
2 Correct 5 ms 7844 KB Output is correct
3 Correct 4 ms 7764 KB Output is correct
4 Correct 4 ms 7848 KB Output is correct
5 Correct 4 ms 7764 KB Output is correct
6 Correct 5 ms 7764 KB Output is correct
7 Correct 4 ms 7840 KB Output is correct
8 Correct 4 ms 7764 KB Output is correct
9 Correct 4 ms 7844 KB Output is correct
10 Correct 5 ms 7764 KB Output is correct
11 Correct 5 ms 7844 KB Output is correct
12 Correct 5 ms 7764 KB Output is correct
13 Correct 5 ms 7764 KB Output is correct
14 Correct 5 ms 7764 KB Output is correct
15 Correct 4 ms 7844 KB Output is correct
16 Correct 5 ms 7840 KB Output is correct
17 Correct 5 ms 7844 KB Output is correct
18 Correct 5 ms 7764 KB Output is correct
19 Correct 5 ms 7864 KB Output is correct
20 Correct 4 ms 7840 KB Output is correct
21 Correct 5 ms 7976 KB Output is correct
22 Correct 5 ms 7892 KB Output is correct
23 Correct 5 ms 7892 KB Output is correct
24 Correct 6 ms 7884 KB Output is correct
25 Correct 6 ms 7892 KB Output is correct
26 Correct 5 ms 7840 KB Output is correct
27 Correct 5 ms 7892 KB Output is correct
28 Correct 5 ms 7892 KB Output is correct
29 Correct 5 ms 7892 KB Output is correct
30 Correct 5 ms 7844 KB Output is correct
31 Correct 5 ms 7892 KB Output is correct
32 Correct 5 ms 7840 KB Output is correct
33 Correct 5 ms 7892 KB Output is correct
34 Correct 6 ms 7892 KB Output is correct
35 Correct 5 ms 7892 KB Output is correct
36 Correct 5 ms 7892 KB Output is correct
37 Correct 5 ms 7892 KB Output is correct
38 Correct 5 ms 7844 KB Output is correct
39 Correct 5 ms 7892 KB Output is correct
40 Correct 14 ms 7996 KB Output is correct
41 Correct 76 ms 17068 KB Output is correct
42 Correct 126 ms 12360 KB Output is correct
43 Correct 43 ms 12364 KB Output is correct
44 Correct 47 ms 12384 KB Output is correct
45 Correct 49 ms 12352 KB Output is correct
46 Correct 204 ms 16936 KB Output is correct
47 Correct 114 ms 16908 KB Output is correct
48 Correct 105 ms 16980 KB Output is correct
49 Correct 92 ms 16928 KB Output is correct
50 Correct 41 ms 11160 KB Output is correct
51 Correct 37 ms 11140 KB Output is correct
52 Correct 32 ms 11108 KB Output is correct
53 Correct 55 ms 14460 KB Output is correct
54 Correct 54 ms 14436 KB Output is correct
55 Correct 56 ms 14444 KB Output is correct
56 Correct 16 ms 7980 KB Output is correct
57 Correct 19 ms 9552 KB Output is correct
58 Correct 77 ms 15896 KB Output is correct
59 Correct 138 ms 19488 KB Output is correct
60 Correct 74 ms 17632 KB Output is correct
61 Correct 88 ms 17348 KB Output is correct