/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Memory Exceeded ≥479ms ≥256.016 MiB
#2 Memory Exceeded ≥482ms ≥256.016 MiB

Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXN 10005

int tree[MAXN][MAXN];
int depth[MAXN];
int visited[MAXN];

void dfs(int node, int parent, int d) {
    visited[node] = 1;
    depth[node] = d;
    for (int i = 0; i < tree[node][0]; i++) {
        if (!visited[tree[node][i + 1]]) {
            dfs(tree[node][i + 1], node, d + 1);
        }
    }
}

int main() {
    int T;
    scanf("%d", &T);

    while (T--) {
        int N, Q;
        scanf("%d%d", &N, &Q);

        memset(tree, 0, sizeof(tree));
        memset(visited, 0, sizeof(visited));
        memset(depth, 0, sizeof(depth));

        for (int i = 0; i < N - 1; i++) {
            int U, V;
            scanf("%d%d", &U, &V);
            tree[U][0]++;
            tree[U][tree[U][0]] = V;
            tree[V][0]++;
            tree[V][tree[V][0]] = U;
        }

        dfs(1, -1, 0);

        while (Q--) {
            int X;
            scanf("%d", &X);
            int ans = 0;
            for (int i = 1; i <= N; i++) {
                if (depth[i] <= X) {
                    ans++;
                }
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Contest
Brain Booster #3
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-06 15:58:02
Judged At
2024-11-11 03:33:37
Judged By
Score
0
Total Time
≥482ms
Peak Memory
≥256.016 MiB