#include #include #include #define pb push_back #define ll long long #define pii pair #define debug printf using namespace std; #define maxn 300300 vector L[maxn]; int tot; int dfs(int v,int r,int p=-1){ int max_need = 0, max_give = 0; for(int kid : L[v]){ if(kid == p) continue; int val = dfs(kid,r,v); if(val < 0) max_need = max(max_need, -val); else max_give = max(max_give,val); } if(max_need == r){ tot++; return r; } if(max_give - 1 >= max_need){ if(max_give == 0) return -1; return max(max_give - 1, 0); } else { if(v == 0 && (max_need > 0 || max_give == 0) ) tot++; if(max_need == 0){ if(max_give > 0) return 0; else return -1; } return -(max_need + 1); } } int main(){ int n,k; scanf("%d%d",&n,&k); for(int i=0;i