/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 5.02 MiB
#2 Accepted 5ms 4.984 MiB
#3 Accepted 77ms 7.277 MiB
#4 Accepted 4ms 5.023 MiB
#5 Accepted 5ms 5.066 MiB

Code

// BISMILLAH

#include "bits/stdc++.h"

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 200005, inf = 1000000005;

int N, q;
std::vector<int> g[mxN];
int lev[mxN];

void dfs(int u, int p, int l) {
    lev[u] = l;
    for (auto v : g[u]) {
        if (v != p) {
            dfs(v, u, l + 1);
        }
    }
}

void clear(int N) {
    for (int i = 1; i <= N; i++) {
        g[i].clear();
    }
}

signed main() {
    // fastIO;
	int testCases=1;
	scanf("%lld",&testCases);
	// std::cin >> testCases;

    // pre();

    for (int T = 1; T <= testCases; T++) {
        scanf("%d%d", &N, &q);
        for (int i =0,u,v; i < N-1; i++) {
            scanf("%d%d", &u, &v);
            g[u].push_back(v);
            g[v].push_back(u);
        }

        dfs(1, -1, 0);
        int ans[N + 1] = {0};
        for (int i = 1; i <= N; i++) {
            ans[lev[i]]++;
        }
        for (int i = 1; i <= N; i++) {
            ans[i] += ans[i - 1];
        }
        for (int i = 0, x; i < q; i++) {
            scanf("%d", &x);
            printf("%d\n", ans[x]);
        }
        clear(N);
    }
	
	return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Language
C++17 (G++ 13.2.0)
Submit At
2024-05-07 18:56:09
Judged At
2024-11-11 03:30:51
Judged By
Score
100
Total Time
77ms
Peak Memory
7.277 MiB