Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- #define ff first
- #define ss second
- #define int long long
- #define pb push_back
- #define mp make_pair
- #define pii pair<int,int>
- #define vi vector<int>
- #define mii map<int,int>
- #define pqb priority_queue<int>
- #define pqs priority_queue<int,vi,greater<int> >
- #define setbits(x) __builtin_popcountll(x)
- #define zrobits(x) __builtin_ctzll(x)
- #define mod 1000000007
- #define inf 1e18
- #define ps(x,y) fixed<<setprecision(y)<<x
- #define mk(arr,n,type) type *arr=new type[n];
- #define w(x) int x; cin>>x; while(x--)
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- #define fastio ios_base::sync_with_stdio(0); cin.tie(0);
- int32_t main()
- {
- int tt;cin>>tt;
- for(int t=1;t<=tt;t++)
- {
- int n,a,b,alp,o;cin>>n>>alp;
- vector<vector<int>> g(n);
- for(int i=0;i<n-1;i++)
- {
- cin>>a>>b;a--;b--;
- g[a].pb(b);
- g[b].pb(a);
- }
- for(int i=0;i<alp;i++) cin>>o;
- queue<int> q; vi h(n,-1);
- h[0]=0;q.push(0);
- while(!q.empty())
- {
- int temp=q.front();q.pop();
- for(auto x:g[temp])
- {
- if(h[x]==-1)
- {
- h[x]=1+h[temp];
- q.push(x);
- }
- }
- }
- // for(int i=0;i<n;i++) cout<<i<<" ** "<<h[i]<<endl;
- vi lvl(n,0);
- for(int i=0;i<n;i++) lvl[h[i]]++;
- for(int i=1;i<n;i++) lvl[i]+=lvl[i-1];
- // for(int i=0;i<n;i++) cout<<i<<" "<<lvl[i]<<endl;
- int ans;
- for(int i=0;i<n;i++)
- {
- if(lvl[i]<=alp) ans=lvl[i];
- }
- cout<<"Case #"<<t<<": "<<ans<<"\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment