/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 344.0 KiB
#3 Runtime Error 45ms 1.848 MiB
#4 Runtime Error 2ms 564.0 KiB

Code

// بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
// In the Name of Allah, the Beneficent, the Merciful.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define vi vector<int>
#define vl vector<long long>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define inv(a) for(auto &it : a) cin >> it;
#define outv(a) for(auto &it : a) cout << it << " ";cout<<"\n"
#define outv1(a) for(auto &it : a) cout << it << " "<<"\n";cout<<"\n"
#define pb push_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define inf 1e9
// #define double long double
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
 




void solve(int tc) {
    int n,q;
    cin>>n>>q;
    vi tr[n+1];
    for (int i = 0; i < n; i++)
    {
        int  u,v;
        cin>>u>>v;
        tr[u].pb(v);
        tr[v].pb(u);
    }

    vi vis(n+1, 0);
    vi level(n+1, 0);
    queue<int> qu;
    qu.push(1);
    vis[1]=1;

    while (!qu.empty())
    {
        int now = qu.front();
        qu.pop();
        vis[now]=1;
        for(auto &it: tr[now]) {
            if(!vis[it]) {
                qu.push(it);
                vis[it]=1;
                level[it]=level[now]+1;
            }
        }
    }
    
    sort(all(level));
    level.erase(level.begin());
    // outv(level);
    int lo = -1;
    for (int i = 1; i <= q; i++)
    {
        int hi; cin>>hi;
        cout<<lower_bound(all(level), hi-1)-level.begin()<<endl;
    }
}

int32_t main() {
    fastio;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    
    int tc=1;
    cin>>tc;
    for (int i = 1; i <= tc; i++)
    {
        solve(i);
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-08 10:31:20
Judged At
2024-11-11 03:30:27
Judged By
Score
10
Total Time
45ms
Peak Memory
1.848 MiB