/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 2.77 MiB
#2 Wrong Answer 3ms 2.715 MiB
#3 Wrong Answer 39ms 5.391 MiB

Code

//....................................<In the name of Allah>...............................//

//.................................<b_bitsmillahir Rahmanir Rahim>...................................//
// Author : Riaj Udd_bitn

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pii;
typedef pair<double, double> pdd;

typedef double dl;

#define lower(a, b) lower_bound((a).begin(), (a).end(), b) - (a).begin()
#define mem(a, b) memset(a, b, sizeof(a));

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

#define fraction(a)               \
    cout.unsetf(ios::floatfield); \
    cout.precision(a);            \
    cout.setf(ios::fined, ios::floatfield);
//////////////////////////////////////////
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p)
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template <typename T>
ostream &operator<<(ostream &os, const set<T> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v)
{
    os << "[";
    for (auto it = v.begin(); it != v.end(); ++it)
    {
        if (it != v.begin())
            os << ", ";
        os << it->first << " = " << it->second;
    }
    return os << "]";
}

#define dbg(args...)            \
    do                          \
    {                           \
        cerr << #args << " : "; \
        faltu(args);            \
    } while (0)

void faltu()
{
    cerr << endl;
}

template <typename T>
void faltu(T a[], ll n)
{
    for (ll i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename... hello>
void faltu(T arg, const hello &...rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

///////////b_bitt-manipulation///////////////
#define Mb(msk) 63 - __builtin_clzll(msk)
#define Lb(msk) __builtin_ctzll(msk)
#define ONE(msk) __builtin_popkll(msk)
#define CHECK(msk, b_bitt) (msk & (1LL << b_bitt))
#define ON(msk, b_bitt) (msk | (1LL << b_bitt))
#define Off(msk, b_bitt) (msk & ~(1LL << b_bitt))
#define CHANGE(msk, b_bitt) (msk ^ (1LL << b_bitt))

//////////////
const int N = 1e5 + 10;
vector<int> g[N];
int dep[N];
int mx_dep;
void dfs(int node, int par, int x)
{
    if (node == 1)
        dep[x] = 1;
    else
        dep[x] = dep[x - 1];
    mx_dep = max(mx_dep, x);
    for (auto u : g[node])
    {
        if (u != par)
        {
            dep[x]++;
            dfs(u, node, x + 1);
        }
    }
}
void solve()
{
    int n, qry;
    cin >> n >> qry;
    mx_dep = 0;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1, -1, 0);
    int p = 1;
    while (qry--)
    {
        int tim;
        cin >> tim;
        if (tim >= mx_dep)
            cout << n << "\n";
        else
            cout << dep[tim] << "\n";
    }
    for (int i = 0; i <= n; i++)
        g[i].clear(), dep[i] = 0;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-02 16:37:38
Judged At
2024-11-11 02:51:38
Judged By
Score
5
Total Time
39ms
Peak Memory
5.391 MiB