ash_sinha

Untitled

Sep 18th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. using namespace __gnu_pbds;
  4. using namespace std;
  5.  
  6. #define ff first
  7. #define ss second
  8. #define int long long
  9. #define pb push_back
  10. #define mp make_pair
  11. #define pii pair<int,int>
  12. #define vi vector<int>
  13. #define mii map<int,int>
  14. #define pqb priority_queue<int>
  15. #define pqs priority_queue<int,vi,greater<int> >
  16. #define setbits(x) __builtin_popcountll(x)
  17. #define zrobits(x) __builtin_ctzll(x)
  18. #define mod 1000000007
  19. #define inf 1e18
  20. #define ps(x,y) fixed<<setprecision(y)<<x
  21. #define mk(arr,n,type) type *arr=new type[n];
  22. #define w(x) int x; cin>>x; while(x--)
  23. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  24. #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
  25. int32_t main()
  26. {
  27. int tt;cin>>tt;
  28. for(int t=1;t<=tt;t++)
  29. {
  30. int n,a,b,alp,o;cin>>n>>alp;
  31. vector<vector<int>> g(n);
  32. for(int i=0;i<n-1;i++)
  33. {
  34. cin>>a>>b;a--;b--;
  35. g[a].pb(b);
  36. g[b].pb(a);
  37. }
  38. for(int i=0;i<alp;i++) cin>>o;
  39. queue<int> q; vi h(n,-1);
  40. h[0]=0;q.push(0);
  41. while(!q.empty())
  42. {
  43. int temp=q.front();q.pop();
  44. for(auto x:g[temp])
  45. {
  46. if(h[x]==-1)
  47. {
  48. h[x]=1+h[temp];
  49. q.push(x);
  50. }
  51. }
  52. }
  53. // for(int i=0;i<n;i++) cout<<i<<" ** "<<h[i]<<endl;
  54.  
  55. vi lvl(n,0);
  56. for(int i=0;i<n;i++) lvl[h[i]]++;
  57. for(int i=1;i<n;i++) lvl[i]+=lvl[i-1];
  58. // for(int i=0;i<n;i++) cout<<i<<" "<<lvl[i]<<endl;
  59. int ans;
  60. for(int i=0;i<n;i++)
  61. {
  62. if(lvl[i]<=alp) ans=lvl[i];
  63. }
  64.  
  65. cout<<"Case #"<<t<<": "<<ans<<"\n";
  66.  
  67. }
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment