-
Notifications
You must be signed in to change notification settings - Fork 0
/
Water Container System
66 lines (62 loc) · 1.01 KB
/
Water Container System
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<vector<int>> adj;
vector<int> vis,dis;
void dfs(int node,int par,int d)
{
vis[node]=1;
dis[node]=d;
for(auto it:adj[node]){
if(it!=par){
dfs(it,node,d+1);
}
}
return;
}
void solve()
{
int n,q;
cin>>n>>q;
adj.assign(n+1,{});
vis.assign(n+1,0);
dis.assign(n+1,0);
map<ll,ll> mp;
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(1,0,0);
for(int i=1;i<=n;i++){
mp[dis[i]]++;
}
int u=q;
while(q--){
int x;
cin>>x;
}
ll total=0;
for(int i=0;i<=n;i++){
total+=mp[i];
if(total>u){
total-=mp[i];
break;
}
}
cout<<total;
}
int main()
{
//freopen("a.txt","r",stdin);
ll t;
cin>>t;
for(ll iop=1;iop<=t;iop++)
{
cout<<"Case #"<<iop<<": ";
solve();
cout<<endl;
}
}