/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 436.0 KiB
#3 Accepted 280ms 2.168 MiB
#4 Accepted 1ms 532.0 KiB
#5 Accepted 1ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1e9+7;
const int N = 1e5+10;
const long long int inf = 1e18+10;

int main(){ 
  int t;
  cin>>t;
  for(int i=1;i<=t;i++){ 
    int n,q;
    cin>>n>>q;
    vector<int> adj[n+10];
    vector<int> lvl(n+1,0);
    vector<int> vis(n+10,0);
    for(int i=1;i<n;i++){
      int a,b;
      cin>>a>>b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    queue<int> qu;
    qu.push(1);
    vis[1]=1;
    while(!qu.empty()){
      int u = qu.front(); qu.pop();
      for(int v:adj[u]){
        if(vis[v]) continue;
        vis[v]=1;
        qu.push(v);
        lvl[v]=lvl[u]+1;
      }
    }
     sort(lvl.begin(),lvl.end()); 
     while(q--){
      int num;  cin>>num;
      cout<<upper_bound(lvl.begin(),lvl.end(),num)-lvl.begin()-1<<endl;
     }
  }
  return 0;
}
 

Information

Submit By
Type
Submission
Problem
P1053 Water on Tree
Language
C++20 (G++ 13.2.0)
Submit At
2024-10-02 11:24:10
Judged At
2024-11-11 02:51:40
Judged By
Score
100
Total Time
280ms
Peak Memory
2.168 MiB