답안 #589413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
589413 2022-07-04T15:53:53 Z Do_you_copy Cat in a tree (BOI17_catinatree) C++14
51 / 100
29 ms 18376 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;

int n, d;
int depth[maxN];
int a[maxN];
int deg[maxN];
vector <int> adj[maxN];
bool visited[maxN];

void predfs(int u, int p){
    for (const int &i: adj[u]){
        if (i == p) continue;
        depth[i] = depth[u] + 1;
        predfs(i, u);
    }
}

void dfs(int u, int p, int d){
    visited[u] = 1;
    if (d <= deg[u]) return;
    deg[u] = d;
    for (const int &i: adj[u]){
        if (i == p) continue;
        dfs(i, u, d - 1);
    }
}

void Init(){
    cin >> n >> d;
    for (int i = 1; i < n; ++i){
        int u; cin >> u;
        adj[u].pb(i);
        adj[i].pb(u);
    }
    predfs(0, 0);
    iota(a, a + n, 0);
    sort(a, a + n,[](const auto &i, const auto &j){
        return depth[i] > depth[j];
    });
    int ans = 0;
    for (int i = 0; i < n; ++i){
        if (!deg[a[i]]){
            dfs(a[i], a[i], d);
            ++ans;
        }
    }
    cout << ans;
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

catinatree.cpp: In function 'int main()':
catinatree.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2688 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2684 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2688 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2688 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2684 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2688 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2684 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 2 ms 2772 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 2772 KB Output is correct
38 Correct 2 ms 2772 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2688 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2684 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2684 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 1 ms 2688 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 3 ms 2772 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 2 ms 2684 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2688 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 2 ms 2772 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 2772 KB Output is correct
38 Correct 2 ms 2772 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Runtime error 29 ms 18376 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -