/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 472.0 KiB
#3 Accepted 239ms 4.016 MiB
#4 Wrong Answer 2ms 532.0 KiB

Code

#include<bits/stdc++.h>

using namespace std;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define   ll          long long
#define   pb          push_back
#define   F           first
#define   S           second
#define   pII         pair<ll, ll>
#define   all(v)      v.begin(),v.end()
#define   allr(v)     v.rbegin(),v.rend()
#define   Endl        "\n"
#define   Case()      cout<<"Case "<<++cs<<": "
#define   bug(a)      cerr<<#a<<" : "<<a<<endl
#define   Tc()        ll T, cs=0; cin>>T; hell:  while(T--)
#define   Tanmoy      ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0)

const ll Mod=1e9+7, MAX=1e6+10, SZ=2e5+5, N=1e13;
ll a[MAX], b[MAX];

int fx8[]={1, -1, 0, 0, 1, 1, -1, -1};
int fy8[]={0, 0, 1, -1, 1, -1, 1, -1};
int fx4[]={1, -1, 0, 0};
int fy4[]={0, 0, 1, -1};


void bfs(vector<vector<int> >& adjList, int startNode, vector<bool>& visited, vector<int>& dis)
{

    queue<int> q;

    visited[startNode] = true;
    q.push(startNode);
    dis[startNode] = 0;

    while(!q.empty()) {

        int currentNode = q.front();
        q.pop();
        //cout << currentNode << " ";

        for(int neighbor : adjList[currentNode]) {
            if (!visited[neighbor]) {
                visited[neighbor] = true;
                q.push(neighbor);
                dis[neighbor] = dis[currentNode] + 1;
            }
        }
    }
}



int main()
{

     Tanmoy;
     ///  freopen("in.txt", "r", stdin);


     Tc(){

         ll n, m, sum=0;


         cin>>n>>m;
         vector<vector<int>>adjList(n+1);
         vector<bool>visited(n+1, false);
         vector<int>dis(n+1, 0), v(n+1, 0);


         for(int i=0; i<n-1; i++){
            int x, y;
            cin>>x>>y;
            adjList[x].pb(y);
           // adjList[y].pb(x);
         }

         vector<pair<int, int>>Q, ans;
         for(int i=1; i<=m; i++){
             cin>>a[i];
             Q.pb({a[i], i});
         }
         sort(all(Q));

         bfs(adjList, 1, visited, dis);

         map<int, int>mp;

         int mx=0;
         for(int i=1; i<=n; i++){
             mp[dis[i]]++;
             if(dis[i]>=mx)mx=dis[i];
         }

         v[0]=0;
         for(int i=1; i<=n; i++){
             v[i]=mp[i];
         }

//         for(int i=0; i<=n; i++){
//            cout<<v[i]<<" ";
//         }

         for(int i=1; i<=n; i++){
            v[i]=v[i]+v[i-1];
         }
//         for(int i=0; i<=n; i++){
//            cout<<v[i]<<" ";
//            }
//        cout<<endl;
//
//          for(auto it: Q){
//            cout<<it.F<<" "<<it.S<<endl;
//          }

         for(auto i: Q){
            if(i.F>n){
                ans.pb({i.S, v[n]+1});
            }
            else ans.pb({i.S, v[i.F]+1});
         }
         sort(all(ans));

         for(auto it: ans){
            cout<<it.S<<endl;
         }


     }

    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 17:12:02
Judged At
2024-11-11 03:32:30
Judged By
Score
75
Total Time
239ms
Peak Memory
4.016 MiB