/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Time Exceeded ≥1098ms ≥2.863 MiB
#4 Accepted 2ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB

Code

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int>> tr;
vector<int> dh;

void dfs(int nd, int pt, int d) {
    dh[nd] = d;
    for (int ch : tr[nd]) {
        if (ch != pt) {
            dfs(ch, nd, d + 1);
        }
    }
}

int main() {
    int t;
    cin >> t;

    while (t--) {
        int n, q;
        cin >> n >> q;

        tr.assign(n + 1, vector<int>());
        dh.assign(n + 1, 0);

        for (int i = 1; i < n; ++i) {
            int u, v;
            cin >> u >> v;
            tr[u].push_back(v);
            tr[v].push_back(u);
        }

        dfs(1, 0, 0);

        for (int i = 0; i < q; ++i) {
            int x;
            cin >> x;

            int count = 0;
            for (int j = 1; j <= n; ++j) {
                if (dh[j] <= x) {
                    count++;
                }
            }

            cout << count << endl;
        }
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Contest
Brain Booster #3
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-06 15:24:46
Judged At
2024-11-11 03:34:29
Judged By
Score
30
Total Time
≥1098ms
Peak Memory
≥2.863 MiB