#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
//#define int long long
const int mod =  998244353;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b/=2, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

int du[200000];
vector<int> G[200000];
int n,k;
int ru[200000];
int lev[200000];
int vis[200000];
queue<int> q,q2;
signed main()
{
    io;
    int mx=0;
    cin>>n>>k;
    rep(i,1,n-1){
        int l,r;cin>>l>>r;
        G[l].pb(r);
        G[r].pb(l);
        du[l]++; du[r]++;
    }
    int fl=1;
    rep(i,1,n) if(du[i]==1)q.push(i),vis[i]=1;
    int cnt=0;
    int c=0;
    map<int,int> in;
    while(!q.empty()){
        cnt++;
        int o=0;
        while(!q.empty()){
        int t=q.front();q.pop();
        c++;
        o++;
        if(du[t] != 1 && ru[t] < 3){
            fl=0;break;
        }
        for(auto &i:G[t]){
                if(!in[i]){
                    ru[i]++;
                    if(!vis[i]){
                       q2.push(i);
                        vis[i]=1;
                    }
                }
            }
        }
        if(q2.empty()){
            fl &= (o==1);
        }
       // in.clear();
        while(!q2.empty()){
            int t=q2.front();q2.pop();
            q.push(t);
            in[t]=1;
        }

        }
   // cout<<fl <<" "<<cnt<<endl;
    if(fl && cnt == k+1 && c == n){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;

//
    getchar(); //cin>>n
    getchar();
}
/*

3
3
RRLLL

3
2
RRLL

*/


#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
//#define int long long
const int mod =  998244353;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b/=2, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

int du[200000];
vector<int> G[200000];
int n,k;
int ru[200000];
int lev[200000];
int vis[200000];
queue<int> q,q2;
signed main()
{
    io;
    int mx=0;
    cin>>n>>k;
    rep(i,1,n-1){
        int l,r;cin>>l>>r;
        G[l].pb(r);
        G[r].pb(l);
        du[l]++; du[r]++;
    }
    int fl=1;
    map<int,int> in;
    rep(i,1,n) if(du[i]==1)q.push(i),vis[i]=1,in[i]=1;
    int cnt=0;
    int c=0;
    while(!q.empty()){
        cnt++;
        int o=0;
        while(!q.empty()){
        int t=q.front();q.pop();
        int kk=0;
         for(auto &i:G[t]){
             if(!vis[i]){
                 kk = 1;
             }
         }
        // ru[t]+=kk;
        c++;
        o++;
        if(du[t] != 1 && ru[t] < 3){
            fl=0;break;
        }
        for(auto &i:G[t]){
                if(!in[i]){
                    ru[i]++;
                    if(!vis[i]){
                       q2.push(i);
                        vis[i]=1;
                    }
                }
            }
        }
        if(q2.empty()){
            fl &= (o==1);
        }
        if(c==1 && !q2.empty()){
            fl =0;
        }
       // in.clear();
        while(!q2.empty()){
            int t=q2.front();q2.pop();
            q.push(t);
            in[t]=1;
        }

        }
   // cout<<fl <<" "<<cnt<<endl;
    if(fl && cnt == k+1 && c == n){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;

//
    getchar(); //cin>>n
    getchar();
}
/*

3
3
RRLLL

3
2
RRLL

*/


#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
//#define int long long
const int mod =  998244353;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b/=2, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

int du[200000];
vector<int> G[200000];
int n,k;
int ru[200000];
int lev[200000];
int vis[200000];
queue<int> q,q2;
signed main()
{
    io;
    int mx=0;
    cin>>n>>k;
    rep(i,1,n-1){
        int l,r;cin>>l>>r;
        G[l].pb(r);
        G[r].pb(l);
        du[l]++; du[r]++;
    }
    int fl=1;
    map<int,int> in;
    rep(i,1,n) if(du[i]==1)q.push(i),vis[i]=1,in[i]=1,lev[i]=1;
    int cnt=0;
    int c=0;
    while(!q.empty()){
        cnt++;
        int o=0;
        while(!q.empty()){
        int t=q.front();q.pop();
        // ru[t]+=kk;
        int kk=-1;
        for (auto &i : G[t]){
            if(in[i]){
                if(kk==-1){
                    lev[t] = lev[i] + 1;
                    kk=1;
                }
                else {
                    if(lev[t] != lev[i] + 1){
                        fl=0;
                      //  cout<<t<<"--"<<i<<endl;
                     //   cout<<lev[t]<<"----"<<lev[i]<<endl;
                    }
                }
            }
        }
        c++;
            o++;
        if(du[t] != 1 && ru[t] < 3){
            fl=0;break;
        }
        for(auto &i:G[t]){
                if(!in[i]){
                    ru[i]++;
                    if(!vis[i]){

                       q2.push(i);
                        vis[i]=1;
                    }
                }
            }
        }
        if(q2.empty()){
            fl &= (o==1);
        }
   /*     if(c==1 && !q2.empty()){
            fl =0;
        }*/
       // in.clear();
        while(!q2.empty()){
            int t=q2.front();q2.pop();
            q.push(t);
            in[t]=1;
        }

        }
   // cout<<fl <<" "<<cnt<<endl;
    if(fl && cnt == k+1 && c == n){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;

//
    getchar(); //cin>>n
    getchar();
}
/*

3
3
RRLLL

3
2
RRLL

*/


#include <bits/stdc++.h>
using namespace std;

const int N = 100100;

int n, k;
vector<int> adj[N];
int deg[N], dep[N], freq[N], root;
bool mark[N];

bool dfs(int v, int on, int par) {
    mark[v] = 1;
    bool ans = 1;
    if (par != -1) {
        ans &= dep[v] < dep[root];
    }
    for (int u : adj[v]) {
        if (u == par) {
            continue;
        }
        ans &= dfs(u, on - 1, v);
    }
    if (v == root) {
        ans &= deg[v] >= 3;
    } else if (deg[v] == 1) {
        ans &= on == 0;
    } else {
        ans &= deg[v] >= 4;
        ans &= on > 0;
    }
    //cout << v << ' ' << on << ' ' << ans << '\n';
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    memset(dep, -1, sizeof dep);
    cin >> n >> k;
    if (n == 1) {
        cout << "No\n";
        return 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
        deg[v]++;
        deg[u]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            q.push(i);
            dep[i] = 0;
        }
    }
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : adj[v]) {
            if (dep[u] != -1) {
                continue;
            }
            dep[u] = dep[v] + 1;
            freq[u] = 1;
            q.push(u);
        }
    }
    int id = -1;
    for (int i = 1; i <= n; i++) {
        //cout << i << ' ' << dep[i] << ' ' << root << '\n';
        if (id == -1 || dep[i] > dep[id]) {
            id = i;
        }
    }
    root = id;
    if (dfs(id, k, -1) && dep[id] == k) {
        bool h = 0;
        for (int i = 1; i <= n; i++) {
            h |= !mark[i];
            h |= (i != root && dep[i] == dep[root]);
        }
        if (!h) cout << "Yes\n";
        else cout << "No\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100100;

int n, q;
vector<int> adj[N];
int deg[N], dep[N], root;

bool dfs(int v, int par) {
    bool ans = 1;
    if (par != -1) {
        ans &= dep[v] < dep[root];
    }
    for (int u : adj[v]) {
        if (u == par) {
            continue;
        }
        ans &= dfs(u, v);
    }
    if (deg[v] > 1) {
        if (v == root) ans &= deg[v] >= 3;
        else ans &= deg[v] >= 4;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    memset(dep, -1, sizeof dep);
    cin >> n >> q;
    if (n == 1) {
        cout << "No\n";
        return 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
        deg[v]++;
        deg[u]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            q.push(i);
            dep[i] = 0;
        }
    }
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : adj[v]) {
            if (dep[u] != -1) {
                continue;
            }
            dep[u] = dep[v] + 1;
            q.push(u);
        }
    }
    int id = -1;
    for (int i = 1; i <= n; i++) {
        if (id == -1 || dep[i] > dep[id]) {
            id = i;
        }
    }
    root = id;
    if (dfs(id, -1)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100100;

int n, k;
vector<int> adj[N];
int deg[N], dep[N], root;

bool dfs(int v, int par) {
    bool ans = 1;
    if (par != -1) {
        ans &= dep[v] < dep[root];
    }
    for (int u : adj[v]) {
        if (u == par) {
            continue;
        }
        ans &= dfs(u, v);
    }
    if (deg[v] > 1) {
        if (v == root) ans &= deg[v] >= 3;
        else ans &= deg[v] >= 4;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    memset(dep, -1, sizeof dep);
    cin >> n >> k;
    if (n == 1) {
        cout << "No\n";
        return 0;
    }
    for (int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        adj[v].push_back(u);
        adj[u].push_back(v);
        deg[v]++;
        deg[u]++;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (deg[i] == 1) {
            q.push(i);
            dep[i] = 0;
        }
    }
    while(!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : adj[v]) {
            if (dep[u] != -1) {
                continue;
            }
            dep[u] = dep[v] + 1;
            q.push(u);
        }
    }
    int id = -1;
    for (int i = 1; i <= n; i++) {
        if (id == -1 || dep[i] > dep[id]) {
            id = i;
        }
    }
    root = id;
    if (dfs(id, -1) && dep[id] == k) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=1e5+10;
int n,K;
int head[N],p,du[N],lv[N];
struct ss{int v,last;}G[N<<1];
void add(int a,int b){
	du[a]++;du[b]++;
	G[++p]=(ss){b,head[a]};head[a]=p;
	G[++p]=(ss){a,head[b]};head[b]=p;
}
queue<int> Q;
int cnt,rt;
bool dfs(int a,int fa,int k) {
	int size=0,f=1;
	for(int i=head[a];i;i=G[i].last)if(G[i].v!=fa){
		++size;
		if(!dfs(G[i].v,a,k-1))f=0;
	}
	if(k==0) return !size;
	else return f&&size>=3;
}
int main()
{
	n=read();K=read();
	for(int i=1,a,b;i<n;i++){
		a=read();b=read();add(a,b);
	}
	for(int i=1;i<=n;i++)
	if(du[i]==1){Q.push(i);lv[i]=0;}
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		if((++cnt)==n){rt=u;break;}
		for(int i=head[u];i;i=G[i].last){
			du[G[i].v]--;
			if(du[G[i].v]==1)Q.push(G[i].v);
		}
	}
	printf("%s\n",dfs(rt,0,K)?"Yes":"No");
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=1e5+10;
int n,K;
int head[N],p,du[N],lv[N];
struct ss{int v,last;}G[N<<1];
void add(int a,int b){
	du[a]++;du[b]++;
	G[++p]=(ss){b,head[a]};head[a]=p;
	G[++p]=(ss){a,head[b]};head[b]=p;
}
queue<int> Q;
int son[12][N],ans;
int main()
{
	n=read();K=read();
	for(int i=1,a,b;i<n;i++){
		a=read();b=read();add(a,b);
	}
	for(int i=1;i<=n;i++)
	if(du[i]==1){Q.push(i);lv[i]=0;}
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(int i=11;i>=0;i--)
		if(son[i][u]>=3){lv[u]=i+1;break;}
		if(lv[u]>ans)ans=lv[u];
		for(int i=head[u];i;i=G[i].last){
			du[G[i].v]--;
			son[lv[u]][G[i].v]++;
			if(du[G[i].v]==1)Q.push(G[i].v);
		}
	}
	printf("%s\n",ans==K?"Yes":"No");
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=1e5+10;
int n,K;
int head[N],p,du[N],lv[N];
struct ss{int v,last;}G[N<<1];
void add(int a,int b){
	du[a]++;du[b]++;
	G[++p]=(ss){b,head[a]};head[a]=p;
	G[++p]=(ss){a,head[b]};head[b]=p;
}
queue<int> Q;
int son[12][N],ans;
int main()
{
	n=read();K=read();
	for(int i=1,a,b;i<n;i++){
		a=read();b=read();add(a,b);
	}
	for(int i=1;i<=n;i++)
	if(du[i]==1){Q.push(i);lv[i]=0;}
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(int i=11;i>=0;i--)
		if(son[i][u]>=3){lv[u]=i+1;break;}
		if(lv[u]>ans)ans=lv[u];
		for(int i=head[u];i;i=G[i].last){
			du[G[i].v]--;
			son[lv[u]][G[i].v]++;
			if(du[G[i].v]==1)Q.push(G[i].v);
		}
	}
	printf("%s\n",ans>=K?"Yes":"No");
	return 0;
}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
using namespace std;
const int inf=0x7fffffff;
const double eps=1e-10;
const double pi=acos(-1.0);
//char buf[1<<15],*S=buf,*T=buf;
//char getch(){return S==T&&(T=(S=buf)+fread(buf,1,1<<15,stdin),S==T)?0:*S++;}
inline int read(){
	int x=0,f=1;char ch;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f)return x;else return -x;
}
const int N=1e5+10;
int n,K;
int head[N],p,du[N],lv[N];
struct ss{int v,last;}G[N<<1];
void add(int a,int b){
	du[a]++;du[b]++;
	G[++p]=(ss){b,head[a]};head[a]=p;
	G[++p]=(ss){a,head[b]};head[b]=p;
}
queue<int> Q;
int cnt,rt;
bool dfs(int a,int fa,int k){
	int size=0,f=1;
	for(int i=head[a];i;i=G[i].last)if(G[i].v!=fa){
		++size;
		if(!dfs(G[i].v,a,k-1))f=0;
	}
	if(k==0)return size?1:0;
	else return f&&size>=3;
}
int main()
{
	n=read();K=read();
	for(int i=1,a,b;i<n;i++){a=read();b=read();add(a,b);}
	for(int i=1;i<=n;i++)
	if(du[i]==1){Q.push(i);lv[i]=0;}
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		if((++cnt)==n){rt=u;break;}
		for(int i=head[u];i;i=G[i].last){
			du[G[i].v]--;
			if(du[G[i].v]==1)Q.push(G[i].v);
		}
	}
	printf("%s\n",dfs(rt,0,K)?"Yes":"No");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
vector<int>G[maxn];
int n,k;
vector<int>now;
int vis[maxn],d[maxn];

int main(){
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	for(int i=1;i<=n;i++)
		if(G[i].size()==1){
			vis[i]=1;
			now.push_back(i);
		}
	for(int i=1;i<=k;i++){//k层
		memset(d,0,sizeof d);
		for(int j=0;j<now.size();j++){
			int u=now[j];
			for(int k=0;k<G[u].size();k++){
				if(!vis[G[u][k]])
					d[G[u][k]]++;
			}
		}
		now.clear();
		for(int j=1;j<=n;j++)
			if(!vis[j] && d[j]>=3)
				now.push_back(j);
			else if(!vis[j] && d[j]>0 && d[j]<3){
				puts("NO");
				return 0;
			}
	}

	puts("YES");

}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
vector<int>G[maxn];
int n,k;
vector<int>now;
int vis[maxn],d[maxn];

int main(){
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(G[i].size()==1)
			vis[i]=1;

	for(int i=1;i<=k;i++){
		for(int j=1;j<=n;j++)
			if(vis[j]==i)
				for(int k=0;k<G[j].size();j++)
					d[G[j][k]]++;
		for(int j=1;j<=n;j++)
			if(!vis[j] && d[j]>=3)
				vis[j]=i+1;
			else if(!vis[j] && d[j]<=3 && d[j]>0){
				puts("NO");
				return 0;
			}
	}
	puts("YES");

}


#include<bits/stdc++.h>

using namespace std;

#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);

#define FI first
#define SE second

typedef long long ll;
typedef pair<ll,ll> P;

const int maxn = 1e5 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;

int n, k;
set<int> st[maxn];
int cnt[maxn];
int d[maxn];

int main() {
    scanf("%d%d", &n, &k);
    if(n < 4) {
        printf("No");
        return 0;
    }
    int u, v;
    for(int i = 1; i < n; ++i) {
        scanf("%d%d", &u, &v);
        st[u].insert(v);
        st[v].insert(u);
        d[u]++, d[v]++;
    }
    int num = 0;
    set<int> t;
    for(int i = 1; i <= n; ++i) {
        if(d[i] == 1) {
            int j = *st[i].begin();
            t.insert(j);
            cnt[j]++;
            st[j].erase(st[j].find(i));
            num++;
        }
    }
    int ans = 1;
    set<int> t_;
    while(t.size()) {
        if(t.size() == 1) {
            int j = *t.begin();
            if(cnt[j] < 3) {
                printf("No");
                return 0;
            }
            num++;
            break;
        }
        for(auto i : t) {
            if(cnt[i] < 3 || st[i].size() != 1) {
                printf("No");
                return 0;
            }
            int j = *st[i].begin();
            t_.insert(j);
            cnt[j]++;
            st[j].erase(st[j].find(i));
            num++;
        }
        t.clear();
        for(auto i : t_) {
            t.insert(i);
        }
        t_.clear();
        ans++;
    }
    if(num != n) {
        printf("No");
        return 0;
    }
    if(ans == k) printf("Yes");
    else printf("No");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
vector<int>G[maxn];
int n,k;
vector<int>now;
int vis[maxn],d[maxn];

int main(){
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(G[i].size()==1)
			vis[i]=1;

	for(int i=1;i<=k;i++){
		memset(d,0,sizeof d);
		for(int j=1;j<=n;j++)
			if(vis[j]==i)
				for(int k=0;k<G[j].size();j++)
					d[G[j][k]]++;
		for(int j=1;j<=n;j++)
			if(!vis[j] && d[j]>=3)
				vis[j]=i+1;
			else if(!vis[j] && d[j]<3 && d[j]>0){
				puts("NO");
				return 0;
			}
	}
	puts("YES");

}


#include<bits/stdc++.h>
using namespace std;
#define maxn 200005
vector<int>G[maxn];
int n,k;
vector<int>now;
int vis[maxn],d[maxn];

int main(){
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(G[i].size()==1)
			vis[i]=1;

	for(int i=1;i<=k;i++){
		for(int j=1;j<=n;j++)
			if(vis[j]==i)
				for(int k=0;k<G[j].size();j++)
					d[G[j][k]]++;
		for(int j=1;j<=n;j++)
			if(!vis[j] && d[j]>=3)
				vis[j]=i+1;
			else if(!vis[j] && d[j]<3 && d[j]>0){
				puts("NO");
				return 0;
			}
	}
	puts("YES");

}


#include <bits/stdc++.h>
using namespace std;
#define vi vector
#define pb push_back
#define inf numeric_limits<int>::max()
int n, k;
vi<int> adj[100000+1];
int main(){
	cin >> n >> k;
	for( int i=0; i<n-1; i++){
		int u, v;
		cin >> u >> v;
		u = u - 1;
		v = v - 1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi<int> lvl(n+1,inf);
	queue<int> q1, q2;
	for( int i=0; i<n; i++)
		if(adj[i].size()==1)
			q1.push(i),
			lvl[i]=0;
	while(!q1.empty()){
		while(!q1.empty()){
			int id = q1.front();
			q1.pop();
			int nonv=0;
			for( int i=0; i<adj[id].size(); i++){
				if(lvl[adj[id][i]]!=inf && lvl[adj[id][i]]!=lvl[id]-1 && lvl[adj[id][i]]!=lvl[id]+1){
					cout << "No";
					return 0;
				}
				if(lvl[adj[id][i]]==inf || lvl[adj[id][i]]==lvl[id]+1){
					nonv = nonv + 1;
				}
			}
			if(nonv>1){
				cout << "No";
				return 0;
			}
			if(nonv==1){
				for( int i=0; i<adj[id].size(); i++)
					if(lvl[adj[id][i]]==inf){
						lvl[adj[id][i]]=lvl[id]+1;
						q2.push(adj[id][i]);
						break;
					}
			}
		}
		while(q2.empty()){
			int id  = q2.front();
			q2.pop();
			q1.push(id);
		}
	}
	for( int i=0; i<n; i++){
		if(lvl[i]==0){
			if(adj[i].size()!=1){
				cout << "No";
				return 0;
			}
		}else{
			if(adj[i].size()<3){
				cout << "No";
				return 0;
			}
		}
	}
	int c=0;
	int m=-1;
	for( int i=0; i<n; i++){
		if(lvl[i]>m){
			c=1;
			m=lvl[i];
		}else{
			if(lvl[i]==m){
				c++;
			}
		}
	}
	//for( int i=0; i<n; i++){
	//	cout << " level of i : " << i << " has " << lvl[i] << endl;
	//}
	if(c!=1){
		cout << "No";
		return 0;
	}
	if(m!=k && m!=inf ){
		cout << "No";
		return 0;
	}
	for( int i=0; i<n; i++)
		if(lvl[i]!=0){
			if(lvl[i]==m){
				if(adj[i].size()<3){
					cout << "No";
					return 0;
				}
			}else{
				if(adj[i].size()<=3){
					cout << "No";
					return 0;
				}
			}
		}
	cout << "Yes";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector
#define pb push_back
#define inf numeric_limits<int>::max()
int n, k;
vi<int> adj[100000+1];
int main(){
	cin >> n >> k;
	for( int i=0; i<n-1; i++){
		int u, v;
		cin >> u >> v;
		u = u - 1;
		v = v - 1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi<int> lvl(n+1,inf);
	queue<int> q1, q2;
	for( int i=0; i<n; i++)
		if(adj[i].size()==1)
			q1.push(i),
			lvl[i]=0;
	while(!q1.empty()){
		while(!q1.empty()){
			int id = q1.front();
			q1.pop();
			int nonv=0;
			for( int i=0; i<adj[id].size(); i++){
				if(lvl[adj[id][i]]!=inf && lvl[adj[id][i]]!=lvl[id]-1 && lvl[adj[id][i]]!=lvl[id]+1){
					cout << "No";
					return 0;
				}
				if(lvl[adj[id][i]]==inf || lvl[adj[id][i]]==lvl[id]+1){
					nonv = nonv + 1;
				}
			}
			if(nonv>1){
				cout << "No";
				return 0;
			}
			if(nonv==1){
				for( int i=0; i<adj[id].size(); i++)
					if(lvl[adj[id][i]]==inf){
						lvl[adj[id][i]]=lvl[id]+1;
						q2.push(adj[id][i]);
						break;
					}
			}
		}
		while(q2.empty()){
			int id  = q2.front();
			q2.pop();
			q1.push(id);
		}
	}
	for( int i=0; i<n; i++){
		if(lvl[i]==0){
			if(adj[i].size()!=1){
				cout << "No";
				return 0;
			}
		}else{
			if(adj[i].size()<3){
				cout << "No";
				return 0;
			}
		}
	}
	int c=0;
	int m=-1;
	for( int i=0; i<n; i++){
		if(lvl[i]>m){
			c=1;
			m=lvl[i];
		}else{
			if(lvl[i]==m){
				c++;
			}
		}
	}
	//for( int i=0; i<n; i++){
	//	cout << " level of i : " << i << " has " << lvl[i] << endl;
	//}
	if(c!=1){
		cout << "No";
		return 0;
	}
	if(m!=k && m!=inf ){
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector
#define pb push_back
#define inf numeric_limits<int>::max()
int n, k;
vi<int> adj[100000+1];
int main(){
	cin >> n >> k;
	for( int i=0; i<n-1; i++){
		int u, v;
		cin >> u >> v;
		u = u - 1;
		v = v - 1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi<int> lvl(n,inf);
	queue<int> q1, q2;
	for( int i=0; i<n; i++)
		if(adj[i].size()==1)
			q1.push(i),
			lvl[i]=0;
	while(!q1.empty()){
		while(!q1.empty()){
			int id = q1.front();
			q1.pop();
			int nonv=0;
			for( int i=0; i<adj[id].size(); i++){
				if(lvl[adj[id][i]]!=inf && lvl[adj[id][i]]!=lvl[id]-1 && lvl[adj[id][i]]!=lvl[id]+1){
					cout << "No";
					return 0;
				}
				if(lvl[adj[id][i]]==inf || lvl[adj[id][i]]==lvl[id]+1){
					nonv = nonv + 1;
				}
			}
			if(nonv>1){
				cout << "No";
				return 0;
			}
			if(nonv==1){
				for( int i=0; i<adj[id].size(); i++)
					if(lvl[adj[id][i]]==inf){
						lvl[adj[id][i]]=lvl[id]+1;
						q2.push(adj[id][i]);
						break;
					}
			}
		}
		while(!q2.empty()){
			int id  = q2.front();
			q2.pop();
			q1.push(id);
		}
	}
	for( int i=0; i<n; i++){
		if(lvl[i]==0){
			if(adj[i].size()!=1){
				cout << "No";
				return 0;
			}
		}else{
			if(adj[i].size()<3){
				cout << "No";
				return 0;
			}
		}
	}
	int c=0;
	int m=-1;
	for( int i=0; i<n; i++){
		if(lvl[i]>m){
			c=1;
			m=lvl[i];
		}else{
			if(lvl[i]==m){
				c++;
			}
		}
	}
	for( int i=0; i<n; i++){
		cout << " level of i : " << i << " has " << lvl[i] << endl;
	}
	if(c!=1){
		cout << "No";
		return 0;
	}
	if(m!=k && m!=inf ){
		cout << "No";
		return 0;
	}
	for( int i=0; i<n; i++)
		if(lvl[i]!=0){
			if(lvl[i]==m){
				if(adj[i].size()<3){
					cout << "No";
					return 0;
				}
			}else{
				if(adj[i].size()<=3){
					cout << "No";
					return 0;
				}
			}
		}
	cout << "Yes";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector
#define pb push_back
#define inf numeric_limits<int>::max()
int n, k;
vi<int> adj[100000+1];
int main(){
	cin >> n >> k;
	for( int i=0; i<n-1; i++){
		int u, v;
		cin >> u >> v;
		u = u - 1;
		v = v - 1;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vi<int> lvl(n,inf);
	queue<int> q1, q2;
	for( int i=0; i<n; i++)
		if(adj[i].size()==1)
			q1.push(i),
			lvl[i]=0;
	while(!q1.empty()){
		while(!q1.empty()){
			int id = q1.front();
			q1.pop();
			int nonv=0;
			for( int i=0; i<adj[id].size(); i++){
				if(lvl[adj[id][i]]!=inf && lvl[adj[id][i]]!=lvl[id]-1 && lvl[adj[id][i]]!=lvl[id]+1){
					cout << "No";
					return 0;
				}
				if(lvl[adj[id][i]]==inf || lvl[adj[id][i]]==lvl[id]+1){
					nonv = nonv + 1;
				}
			}
			if(nonv>1){
				cout << "No";
				return 0;
			}
			if(nonv==1){
				for( int i=0; i<adj[id].size(); i++)
					if(lvl[adj[id][i]]==inf){
						lvl[adj[id][i]]=lvl[id]+1;
						q2.push(adj[id][i]);
						break;
					}
			}
		}
		while(!q2.empty()){
			int id  = q2.front();
			q2.pop();
			q1.push(id);
		}
	}
	for( int i=0; i<n; i++){
		if(lvl[i]==0){
			if(adj[i].size()!=1){
				cout << "No";
				return 0;
			}
		}else{
			if(adj[i].size()<3){
				cout << "No";
				return 0;
			}
		}
	}
	int c=0;
	int m=-1;
	for( int i=0; i<n; i++){
		if(lvl[i]>m){
			c=1;
			m=lvl[i];
		}else{
			if(lvl[i]==m){
				c++;
			}
		}
	}
	//for( int i=0; i<n; i++){
	//	cout << " level of i : " << i << " has " << lvl[i] << endl;
	//}
	if(c!=1){
		cout << "No";
		return 0;
	}
	if(m!=k && m!=inf ){
		cout << "No";
		return 0;
	}
	for( int i=0; i<n; i++)
		if(lvl[i]!=0){
			if(lvl[i]==m){
				if(adj[i].size()<3){
					cout << "No";
					return 0;
				}
			}else{
				if(adj[i].size()<=3){
					cout << "No";
					return 0;
				}
			}
		}
	cout << "Yes";
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#define INT long long int
using namespace std;
INT n, k, p, v[2], chk[100010], chk2[100010], R;
bool ok = true;
vector<INT> G[100010];
queue<INT> q;
void dfs(int x, int y, int z)
{
    if( !ok ) return;
    if( z > k or (z != k and z != 0 and G[x].size() < 4) )
    {
        ok = false;
        return;
    }
    for(int w : G[x])
        if( w != y )
            dfs(w, x, z+1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0 ; i < n-1 ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1 ; p < 2 and i <= n ; i++ )
        if( G[i].size() == 1 ) v[p++] = i;
    q.push(v[0]), chk[v[0]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk[y] )
            {
                q.push(y), chk[y] = chk[x]+1;
            }
        }
    }
    q.push(v[1]), chk2[v[1]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk2[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk2[y] )
            {
                q.push(y), chk2[y] = chk2[x]+1;
            }
        }
    }
    if( v[0]*v[1] == 0 ) ok = false;
    for(int i = 1 ; !ok and !R and i <= n ; i++ )
        if( chk[i] == chk2[i] and chk[i] == k+1 and G[i].size() > 1 )
            R = i;
    if( R == 0 ) ok = false;
    else if( G[R].size() < 3 ) ok = false;
    dfs(R, R, 0);
    if( ok ) cout<<"Yes";
    else cout<<"No";
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#define INT long long int
using namespace std;
INT n, k, p, v[2], chk[100010], chk2[100010], R;
bool ok = true;
vector<INT> G[100010];
queue<INT> q;
void dfs(int x, int y, int z)
{
    if( !ok ) return;
    if( z > k or (z != k and z != 0 and G[x].size() < 4) )
    {
        ok = false;
        return;
    }
    for(int w : G[x])
        if( w != y )
            dfs(w, x, z+1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0 ; i < n-1 ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1 ; p < 2 and i <= n ; i++ )
        if( G[i].size() == 1 ) v[p++] = i;
    if( p < 2 ) ok = false;
    q.push(v[0]), chk[v[0]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk[y] )
            {
                q.push(y), chk[y] = chk[x]+1;
            }
        }
    }
    q.push(v[1]), chk2[v[1]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk2[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk2[y] )
            {
                q.push(y), chk2[y] = chk2[x]+1;
            }
        }
    }
    for(int i = 1 ; ok and !R and i <= n ; i++ )
        if( chk[i] == chk2[i] and chk[i] == k+1 and G[i].size() > 1 )
            R = i;
    if( R == 0 ) ok = false;
    else if( G[R].size() < 3 ) ok = false;
    dfs(R, R, 0);
    if( ok ) cout<<"Yes";
    else cout<<"No";
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#define INT long long int
using namespace std;
INT n, k, p, v[2], chk[100010], chk2[100010], R;
bool ok = true;
vector<INT> G[100010];
queue<INT> q;
void dfs(int x, int y, int z)
{
    if( !ok ) return;
    if( z > k or (z != k and z != 0 and G[x].size() < 4) )
    {
        ok = false;
        return;
    }
    for(int w : G[x])
        if( w != y )
            dfs(w, x, z+1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0 ; i < n-1 ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1 ; p < 2 and i <= n ; i++ )
        if( G[i].size() == 1 ) q.push(i), chk[i] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        for(int y : G[x])
        {
            if( !chk[y] )
            {
                q.push(y), chk[y] = chk[x]+1;
            }
        }
    }
    for(int i = 1 ; i <= n ; i++ )
        if( chk[i] == k+1 ) R = i;
    if( R == 0 ) ok = false;
    else if( G[R].size() < 3 ) ok = false;
    dfs(R, R, 0);
    if( ok ) cout<<"Yes";
    else cout<<"No";
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#define INT long long int
using namespace std;
INT n, k, p, v[2], chk[100010], chk2[100010], R;
bool ok = true;
vector<INT> G[100010];
queue<INT> q;
void dfs(int x, int y, int z)
{
    if( !ok ) return;
    if( z > k or (z != k and x != R and G[x].size() < 4) )
    {
        ok = false;
        return;
    }
    for(int w : G[x])
        if( w != y )
            dfs(w, x, z+1);
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i = 0 ; i < n-1 ; i++ )
    {
        int a, b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 1 ; p < 2 and i <= n ; i++ )
        if( G[i].size() == 1 ) v[p++] = i;
    q.push(v[0]), chk[v[0]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk[y] )
            {
                q.push(y), chk[y] = chk[x]+1;
            }
        }
    }
    q.push(v[1]), chk2[v[1]] = 1;
    while( !q.empty() )
    {
        int x = q.front(); q.pop();
        if( chk2[x] > k ) continue;
        for(int y : G[x])
        {
            if( !chk2[y] )
            {
                q.push(y), chk2[y] = chk2[x]+1;
            }
        }
    }
    for(int i = 1 ; !R and i <= n ; i++ )
        if( chk[i] == chk2[i] and chk[i] == k+1 and G[i].size() > 1 )
            R = i;
    if( G[R].size() < 3 ) ok = false;
    dfs(R, R, 0);
    if( ok ) cout<<"Yes";
    else cout<<"No";
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC diagnostic error "-std=c++11"
//#pragma comment(linker, "/STACK:102400000,102400000")
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define debug(x) { cerr << #x << '=' << x << "\n"; }
#define Arr(a, l, r) { cerr << #a << " = {"; REP(_, l, r) cerr << ' ' << a[_]; cerr << " }\n"; }
#define mset(a,b) memset(a,b,sizeof(a))
#define mkpr make_pair
#define ll long long
#define print(x) cout<<x<<"\n"

using namespace std;
const int maxn = 1e5+6;
int N, K, deg[maxn], d[maxn], cnt[maxn], vis[maxn];
vector<int> G[maxn];
queue<int> Q;

void No() {
	exit(0 * puts("No"));
}

int main(){
  ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  cin>>N>>K;
	for(int i = 1, u, v; i < N; i++) {
		cin>>u>>v;
		deg[--u]++;
		deg[--v]++;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i = 0; i < N; i++)
		if(deg[i] == 1) Q.push(i);
	while(!Q.empty()) {
		int x = Q.front(); Q.pop();
		vis[x] = 1;
		if(d[x] > 0 && cnt[x] < 3) No();
		for(auto e : G[x]) {
			if(vis[e]) continue;
			if(d[e] == 0)
				d[e] = d[x] + 1;
			else if(d[e] != d[x] + 1)
				No();
			cnt[e]++;
			if(--deg[e] == 1) Q.push(e);
		}
	}
	puts(*max_element(d, d + N) == K ? "Yes" : "No");

	return 0;
  return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC diagnostic error "-std=c++11"
//#pragma comment(linker, "/STACK:102400000,102400000")
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define debug(x) { cerr << #x << '=' << x << "\n"; }
#define Arr(a, l, r) { cerr << #a << " = {"; REP(_, l, r) cerr << ' ' << a[_]; cerr << " }\n"; }
#define mset(a,b) memset(a,b,sizeof(a))
#define mkpr make_pair
#define ll long long
#define print(x) cout<<x<<"\n"

using namespace std;
const int maxn = 1e5+6;
int n,k,x,y,s,path[maxn];
bool vis[maxn],flag;
vector<int> G[maxn];

int dfs(int v){
	// print(v);
	vis[v] = true;
	int mx = 0,ind = -1,t = -1;
	REP(i,0,G[v].size())if(!vis[G[v][i]]){
		t = dfs(G[v][i]);
		if(t>mx)mx = t,ind = i;
	}
	path[v] = G[v][ind];
	return mx+1;
}

void check(int v,int cur){
	// print(v);
	if(flag)return;
	vis[v] = true;
	if(cur>=k&&G[v].size()!=1&&v!=s)flag = true;
	for(int next:G[v])if(!vis[next])check(next,cur+1);
}

int main(){
  ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  cin>>n>>k;
  REP(i,1,n){
  	cin>>x>>y;
  	G[x].push_back(y);
  	G[y].push_back(x);
  }
  s = -1;
  REP(i,1,n+1)if(G[i].size()==1){
  	s=i;
  	break;
  }
  int maxLength = dfs(s);
  if(!(maxLength&1)||k!=maxLength/2){

  }
  mset(vis,false);
  REP(i,0,k){
  	s = path[s];
  }
  if(G[s].size()<3){
  	print("NO");
  	return 0;
  }
  // print(s);
  check(s,0);
  flag?print("NO"):print("YES");
  // Arr(path,1,n+1);
  return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC diagnostic error "-std=c++11"
//#pragma comment(linker, "/STACK:102400000,102400000")
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define debug(x) { cerr << #x << '=' << x << "\n"; }
#define Arr(a, l, r) { cerr << #a << " = {"; REP(_, l, r) cerr << ' ' << a[_]; cerr << " }\n"; }
#define mset(a,b) memset(a,b,sizeof(a))
#define mkpr make_pair
#define ll long long
#define print(x) cout<<x<<"\n"

using namespace std;
const int maxn = 1e5+6;
int n,k,x,y,s,path[maxn];
bool vis[maxn],flag;
vector<int> G[maxn];

int dfs(int v){
	// print(v);
	vis[v] = true;
	int mx = 0,ind = -1,t = -1;
	REP(i,0,G[v].size())if(!vis[G[v][i]]){
		t = dfs(G[v][i]);
		if(t>mx)mx = t,ind = i;
	}
	path[v] = G[v][ind];
	return mx+1;
}

void check(int v,int cur){
	print(v);
	if(flag)return;
	vis[v] = true;
	if(cur>=k&&G[v].size()!=1&&v!=s)flag = true;
	for(int next:G[v])if(!vis[next])check(next,cur+1);
}

int main(){
  ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  cin>>n>>k;
  REP(i,1,n){
  	cin>>x>>y;
  	G[x].push_back(y);
  	G[y].push_back(x);
  }
  s = -1;
  REP(i,1,n+1)if(G[i].size()==1){
  	s=i;
  	break;
  }
  int maxLength = dfs(s);
  if(!(maxLength&1)||k!=maxLength/2){

  }
  mset(vis,false);
  REP(i,0,k){
  	s = path[s];
  }
  if(G[s].size()<3){
  	print("NO");
  	return 0;
  }
  // print(s);
  check(s,0);
  flag?print("NO"):print("YES");
  // Arr(path,1,n+1);
  return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC diagnostic error "-std=c++11"
//#pragma comment(linker, "/STACK:102400000,102400000")
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define debug(x) { cerr << #x << '=' << x << "\n"; }
#define Arr(a, l, r) { cerr << #a << " = {"; REP(_, l, r) cerr << ' ' << a[_]; cerr << " }\n"; }
#define mset(a,b) memset(a,b,sizeof(a))
#define mkpr make_pair
#define ll long long
#define print(x) cout<<x<<"\n"

using namespace std;
const int maxn = 1e5+6;
int n,k,x,y,s,path[maxn];
bool vis[maxn],flag;
vector<int> G[maxn];

int dfs(int v){
	// print(v);
	vis[v] = true;
	int mx = 0,ind = 0,t = -1;
	REP(i,0,G[v].size())if(!vis[G[v][i]]){
		t = dfs(G[v][i]);
		if(t>mx)mx = t,ind = i;
	}
	path[v] = G[v][ind];
	return mx+1;
}

void check(int v,int cur){
	// print(v);
	if(flag)return;
	vis[v] = true;
	if(cur>=k&&G[v].size()!=1&&v!=s)flag = true;
	for(int next:G[v])if(!vis[next])check(next,cur+1);
}

int main(){
  ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  cin>>n>>k;
  REP(i,1,n){
  	cin>>x>>y;
  	G[x].push_back(y);
  	G[y].push_back(x);
  }
  s = -1;
  REP(i,1,n+1)if(G[i].size()==1){
  	s=i;
  	break;
  }
  int maxLength = dfs(s);
  if(!(maxLength&1)||k!=maxLength/2){

  }
  mset(vis,false);
  REP(i,0,k){
  	s = path[s];
  }
  if(G[s].size()<3){
  	print("NO");
  	return 0;
  }
  // print(s);
  check(s,0);
  flag?print("NO"):print("YES");
  // Arr(path,1,n+1);
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX     100000
int n, k;
vector<int>E[MAX+10], tmp[MAX+10];
bool isLeaf[MAX+10];

bool ok;

void dfs(int node, int par)
{
//    DD(node, par);
    if(E[node].size() == 1)
    {
        isLeaf[node] = true;
        return;
    }
    int leaf, internal;
    leaf = internal = 0;
    for(auto v: E[node])
    {
        if(v != par)
        {
            dfs(v, node);
            if(isLeaf[v])
                leaf++;
            else
                internal++;
        }
    }
//    if(leaf && internal)
//    {
//        ok = false;
//        return;
//    }
    if(leaf && leaf < 3)
    {
        ok = false;
        return;
    }
//    if(internal && internal < 3)
//    {
//        ok = false;
//        return;
//    }
}

int main()
{
//    freopen("maxon.txt", "r", stdin);

    sff(n, k);
    for(int i = 1; i<n; i++)
    {
        int u, v;
        sff(u, v);
        E[u].pb(v);
        E[v].pb(u);
    }
    if(k > 15)
    {
        puts("No");
        return 0;
    }

    ok = true;
    while(k--)
    {
        bool done = false;

            for(int i = 1; i<=n; i++)
            {
                if(E[i].size() >= 3)
                {
                    done = true;
                    dfs(i, -1);
                }
            }

        if(!done)
            ok = false;

        if(!ok)
            break;

        for(int i = 1; i<=n; i++)
        {
            tmp[i].clear();
            if(isLeaf[i] == false)
            {
                for(auto v: E[i])
                {
                    if(isLeaf[v] == false)
                        tmp[i].pb(v);
                }
            }
            E[i] = tmp[i];
        }
    }
    /// check if there's only one node

    int have = 0;
    for(int i = 1; i<=n; i++)
    {
        if(isLeaf[i] == false)
            have++;
    }
    if(have != 1)
        ok = false;
    if(ok)
        puts("Yes");
    else
        puts("No");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX     100000
int n, k;
vector<int>E[MAX+10], tmp[MAX+10];
bool isLeaf[MAX+10];

bool ok;

void dfs(int node, int par)
{
//    DD(node, par);
    if(E[node].size() == 1)
    {
        isLeaf[node] = true;
        return;
    }
    int leaf, internal;
    leaf = internal = 0;
    for(auto v: E[node])
    {
        if(v != par)
        {
            dfs(v, node);
            if(isLeaf[v])
                leaf++;
            else
                internal++;
        }
    }
//    if(leaf && internal)
//    {
//        ok = false;
//        return;
//    }
    if(leaf && leaf < 3)
    {
        ok = false;
        return;
    }
//    if(internal && internal < 3)
//    {
//        ok = false;
//        return;
//    }
}

int main()
{
//    freopen("maxon.txt", "r", stdin);

    sff(n, k);
    for(int i = 1; i<n; i++)
    {
        int u, v;
        sff(u, v);
        E[u].pb(v);
        E[v].pb(u);
    }
    if(k > 15)
    {
        puts("No");
        return 0;
    }

    ok = true;
    while(k--)
    {
        bool done = false;
        for(int i = 1; i<=n; i++)
        {
            if(E[i].size() >= 3)
            {
                bool yes = true;
                for(auto v: E[i])
                {
                    if(E[v].size() == 1)
                    {
                        yes = false;
                        break;
                    }
                }
                if(yes)
                {
                    done = true;
                    dfs(i, -1);
                }
                if(done)
                    break;
            }
        }
        if(!done)
        {
            for(int i = 1; i<=n; i++)
            {
                if(E[i].size() >= 3)
                {
                    done = true;
                    dfs(i, -1);
                }
            }
        }

        if(!done)
            ok = false;

        if(!ok)
            break;

        for(int i = 1; i<=n; i++)
        {
            tmp[i].clear();
            if(isLeaf[i] == false)
            {
                for(auto v: E[i])
                {
                    if(isLeaf[v] == false)
                        tmp[i].pb(v);
                }
            }
            E[i] = tmp[i];
        }
    }
    /// check if there's only one node

    int have = 0;
    for(int i = 1; i<=n; i++)
    {
        if(isLeaf[i] == false)
            have++;
    }
    if(have != 1)
        ok = false;
    if(ok)
        puts("Yes");
    else
        puts("No");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX     100000
int n, k;
vector<int>E[MAX+10], tmp[MAX+10];
bool isLeaf[MAX+10];
int deleted[MAX+10];

bool ok;

void dfs(int node, int par)
{
//    DD(node, par);
    if(E[node].size() == 1)
    {
        isLeaf[node] = true;
        return;
    }
    int leaf, internal;
    leaf = internal = 0;
    for(auto v: E[node])
    {
        if(v != par)
        {
            dfs(v, node);
            if(isLeaf[v])
                leaf++;
            else
                internal++;
        }
    }
    if(leaf && internal)
    {
        ok = false;
        return;
    }
    if(leaf && leaf < 3)
    {
        ok = false;
        return;
    }
    if(internal && internal < 3)
    {
        ok = false;
        return;
    }
}

int main()
{
//    freopen("maxon.txt", "r", stdin);

    sff(n, k);
    for(int i = 1; i<n; i++)
    {
        int u, v;
        sff(u, v);
        E[u].pb(v);
        E[v].pb(u);
    }
    if(k > 15)
    {
        puts("No");
        return 0;
    }

    ok = true;
    while(k--)
    {
        bool done = false;
        for(int i = 1; i<=n; i++)
        {
            if(E[i].size() >= 3)
            {
                bool yes = true;
                for(auto v: E[i])
                {
                    if(E[v].size() == 1)
                    {
                        yes = false;
                        break;
                    }
                }
                if(yes)
                {
                    done = true;
                    dfs(i, -1);
                }
                if(done)
                    break;
            }
        }
        if(!done)
        {
            for(int i = 1; i<=n; i++)
            {
                if(E[i].size() >= 3)
                {
                    done = true;
                    dfs(i, -1);
                }
            }
        }

        if(!done)
            ok = false;

        if(!ok)
            break;

        for(int i = 1; i<=n; i++)
        {
            tmp[i].clear();
            if(isLeaf[i] == false)
            {
                for(auto v: E[i])
                {
                    if(isLeaf[v] == false)
                        tmp[i].pb(v);
                }
            }
            E[i] = tmp[i];
        }
    }
    /// check if there's only one node

    int have = 0;
    for(int i = 1; i<=n; i++)
    {
        if(isLeaf[i] == false)
            have++;
    }
    if(have != 1)
        ok = false;
    if(ok)
        puts("Yes");
    else
        puts("No");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mem(t, v)   memset ((t) , v, sizeof(t))
#define all(x)      x.begin(),x.end()
#define un(x)       x.erase(unique(all(x)), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sl(n)       scanf("%lld", &n)
#define sll(a,b)    scanf("%lld %lld", &a, &b)
#define slll(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define D(x)        cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         cerr << __LINE__ << ": Hi" << '\n'
#define pb          push_back
#define PI          acos(-1.00)
#define xx          first
#define yy          second
#define eps         1e-9

typedef unsigned long long int ULL;
typedef long long int LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

inline int setBit(int N, int pos) { return N=N | (1<<pos); }
inline int resetBit(int N, int pos) { return N= N & ~(1<<pos); }
inline bool checkBit(int N, int pos) { return (bool)(N & (1<<pos)); }

//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction
#define MAX     100000
int n, k;
vector<int>E[MAX+10], tmp[MAX+10];
bool isLeaf[MAX+10];

bool ok;

void dfs(int node, int par)
{
//    DD(node, par);
    if(E[node].size() == 1)
    {
        isLeaf[node] = true;
        return;
    }
    int leaf, internal;
    leaf = internal = 0;
    for(auto v: E[node])
    {
        if(v != par)
        {
            dfs(v, node);
            if(isLeaf[v])
                leaf++;
            else
                internal++;
        }
    }
//    if(leaf && internal)
//    {
//        ok = false;
//        return;
//    }
    if(leaf && leaf < 3)
    {
        ok = false;
        return;
    }
//    if(internal && internal < 3)
//    {
//        ok = false;
//        return;
//    }
}

int main()
{
//    freopen("maxon.txt", "r", stdin);

    sff(n, k);
    for(int i = 1; i<n; i++)
    {
        int u, v;
        sff(u, v);
        E[u].pb(v);
        E[v].pb(u);
    }
    if(k > 15)
    {
        puts("No");
        return 0;
    }

    ok = true;
    while(k--)
    {
        bool done = false;
        for(int i = 1; i<=n; i++)
        {
            if(E[i].size() >= 3)
            {
                bool yes = true;
                for(auto v: E[i])
                {
                    if(E[v].size() == 1)
                    {
                        yes = false;
                        break;
                    }
                }
                if(yes)
                {
                    done = true;
                    dfs(i, -1);
                }
                if(done)
                    break;
            }
        }
        if(!done)
        {
            for(int i = 1; i<=n; i++)
            {
                if(E[i].size() >= 3)
                {
                    done = true;
                    dfs(i, -1);
                    break;
                }
            }
        }

        if(!done)
            ok = false;

        if(!ok)
            break;

        for(int i = 1; i<=n; i++)
        {
            tmp[i].clear();
            if(isLeaf[i] == false)
            {
                for(auto v: E[i])
                {
                    if(isLeaf[v] == false)
                        tmp[i].pb(v);
                }
            }
            E[i] = tmp[i];
        }
    }
    /// check if there's only one node

    int have = 0;
    for(int i = 1; i<=n; i++)
    {
        if(isLeaf[i] == false)
            have++;
    }
    if(have != 1)
        ok = false;
    if(ok)
        puts("Yes");
    else
        puts("No");

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], DD[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    memcpy(DD, D, sizeof D);
    int res = n, TT = 0;
    static bool used[M];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(TT = 1; res > 1; TT++) {
        vector <int> V;
        V.clear();
        for(int i = 1; i <= n; i++) if(!used[i]) {
            if(D[i] == 1) V.push_back(i);
            else if(D[i] == 2) {
                puts("No");
                return 0;
            }
        }
        res -= V.size();
        if(res == 0) {
            puts("No");
            return 0;
        }
        for(int i = 0; i < V.size(); i++) {
            used[V[i]] = 1;
            for(int T = Head[V[i]]; T; T = Next[T]) {
                D[Go[T]]--;
            }
        }
    }
    int cent = 0;
    memcpy(D, DD, sizeof DD);
    for(int i = 1; i <= n; i++) if(!used[i]) cent = i;
    for(int i = 1; i <= n; i++) if(i != cent && (D[i] == 2 || D[i] == 3) || i == cent && D[i] == 2) {
        puts("No");
        return 0;
    }
    puts(TT - 1 == k ? "Yes" : "No");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], DD[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    memcpy(DD, D, sizeof D);
    int res = n, TT = 0;
    static bool used[M];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(TT = 1; res > 1; TT++) {
        vector <int> V;
        V.clear();
        for(int i = 1; i <= n; i++)
            if(D[i] == 1) V.push_back(i);
            else if(D[i] == 2) {
                puts("No");
                return 0;
            }
        res -= V.size();
        if(res == 0) {
            puts("No");
            return 0;
        }
        for(int i = 0; i < V.size(); i++) {
            used[V[i]] = 1;
            for(int T = Head[V[i]]; T; T = Next[T]) {
                D[Go[T]]--;
            }
        }
    }
    int cent = 0;
    memcpy(D, DD, sizeof DD);
    for(int i = 1; i <= n; i++) if(!used[i]) cent = i;
    for(int i = 1; i <= n; i++) if(i != cent && (D[i] == 2 || D[i] == 3) || i == cent && D[i] == 2) {
        puts("No");
        return 0;
    }
    puts(TT - 1 == k ? "Yes" : "No");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    int res = n, TT = 0;
    for(TT = 1; res > 1; TT++) {
        vector <int> V;
        V.clear();
        for(int i = 1; i <= n; i++)
            if(D[i] == 1) V.push_back(i);
            else if(D[i] == 2) {
                puts("No");
                return 0;
            }
        res -= V.size();
        for(int i = 0; i < V.size(); i++)
            for(int T = Head[V[i]]; T; T = Next[T])
                D[V[i]]--, D[Go[T]]--;
    }
    puts(TT - 1 == k ? "Yes" : "No");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    int res = n, TT = 0;
    for(TT = 1; res > 1; TT++) {
        vector <int> V;
        V.clear();
        for(int i = 1; i <= n; i++)
            if(D[i] == 1) V.push_back(i);
            else if(D[i] == 2) {
                puts("No");
                return 0;
            }
        res -= V.size();
        if(res == 0) {
            puts("No");
            return 0;
        }
        for(int i = 0; i < V.size(); i++)
            for(int T = Head[V[i]]; T; T = Next[T]) {
                D[V[i]]--, D[Go[T]]--;
            }
    }
    puts(TT - 1 == k ? "Yes" : "No");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], Dis[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

void DFS(int x, int f = 0) {
    int flag = 0;
    for(int T = Head[x]; T; T = Next[T]) if(Go[T] != f) {
        flag++;
        DFS(Go[T], x);
        if(Dis[Go[T]] != Dis[x] - 1) {
            puts("No");
            exit(0);
        }
    }
    if(flag == 2 || flag == 1) {
        puts("No");
        exit(0);
    }
    if(!flag && Dis[x]) {
        puts("No");
        exit(0);
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    vector <int> V;
    V.clear();
    for(int i = 1; i <= n; i++) if(D[i] == 1) V.push_back(i);
    for(int i = 0; i < V.size(); i++) {
        for(int T = Head[V[i]]; T; T = Next[T])
            if(--D[Go[T]] == 1) V.push_back(Go[T]), Dis[Go[T]] = Dis[V[i]] + 1;
    }
    if(V.empty()) {
        puts("No");
        return 0;
    }
    if(Dis[V.back()] != k) {
        puts("No");
        return 0;
    }
    DFS(V.back());
    puts("Yes");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], DD[M], Dis[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

void DFS(int x, int f = 0) {
    int flag = 0;
    for(int T = Head[x]; T; T = Next[T]) if(Go[T] != f) {
        flag++;
        if(Dis[Go[T]] != Dis[x] - 1) {
            puts("No");
            exit(0);
        }
    }
    if(flag == 2) {
        puts("No");
        exit(0);
    }
    if(!flag && Dis[x]) {
        puts("No");
        exit(0);
    }
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    vector <int> V;
    V.clear();
    for(int i = 1; i <= n; i++) if(D[i] == 1) V.push_back(i);
    for(int i = 0; i < V.size(); i++) {
        for(int T = Head[V[i]]; T; T = Next[T])
            if(--D[Go[T]] == 1) V.push_back(Go[T]), Dis[Go[T]] = Dis[V[i]] + 1;
    }
    if(Dis[V.back()] != k) {
        puts("No");
        return 0;
    }
    DFS(V.back());
    puts("Yes");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], Dis[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

void DFS(int x, int f = 0) {
    int flag = 0;
    for(int T = Head[x]; T; T = Next[T]) if(Go[T] != f) {
        flag++;
        DFS(Go[T], x);
        if(Dis[Go[T]] != Dis[x] - 1) {
            puts("No");
            exit(0);
        }
    }
    if(flag == 2 || flag == 1) {
        puts("No");
        exit(0);
    }
    if(!flag && Dis[x]) {
        puts("No");
        exit(0);
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    vector <int> V;
    V.clear();
    for(int i = 1; i <= n; i++) if(D[i] == 1) V.push_back(i);
    for(int i = 0; i < V.size(); i++) {
        for(int T = Head[V[i]]; T; T = Next[T])
            if(--D[Go[T]] == 1) V.push_back(Go[T]), Dis[Go[T]] = Dis[V[i]] + 1;
    }
    if(Dis[V.back()] != k) {
        puts("No");
        return 0;
    }
    DFS(V.back());
    puts("Yes");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], DD[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

int main() {
    scanf("%d%d", &n, &k);
    /*if(k > 50) {
        puts("No");
        return 0;
    }*/
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    memcpy(DD, D, sizeof D);
    int res = n, TT = 0;
    static bool used[M];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(TT = 1; res > 1; TT++) {
        vector <int> V;
        V.clear();
        for(int i = 1; i <= n; i++)
            if(D[i] == 1) V.push_back(i);
            else if(D[i] == 2) {
                puts("No");
                return 0;
            }
        res -= V.size();
        if(res == 0) {
            puts("No");
            return 0;
        }
        for(int i = 0; i < V.size(); i++) {
            used[V[i]] = 1;
            for(int T = Head[V[i]]; T; T = Next[T]) {
                D[Go[T]]--;
            }
        }
    }
    int cent = 0;
    memcpy(D, DD, sizeof DD);
    for(int i = 1; i <= n; i++) if(!used[i]) cent = i;
    for(int i = 1; i <= n; i++) if(i != cent && (D[i] == 2 || D[i] == 3)) {
        puts("No");
        return 0;
    }
    puts(TT - 1 == k ? "Yes" : "No");
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdlib>

#define M 200010

using namespace std;

int n, k, Head[M], Next[M], Go[M], D[M], Dis[M], Cnt = 0;

void addedge(int x, int y) {
    Go[++Cnt] = y;
    Next[Cnt] = Head[x];
    Head[x] = Cnt;
    D[x]++;
}

void DFS(int x, int f = 0) {
    int flag = 0;
    for(int T = Head[x]; T; T = Next[T]) if(Go[T] != f) {
        flag++;
        DFS(Go[T], x);
        if(Dis[Go[T]] != Dis[x] - 1) {
            puts("No");
            exit(0);
        }
    }
    if(flag == 2) {
        puts("No");
        exit(0);
    }
    if(!flag && Dis[x]) {
        puts("No");
        exit(0);
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for(int i = 1; i < n; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        addedge(a, b);
        addedge(b, a);
    }
    vector <int> V;
    V.clear();
    for(int i = 1; i <= n; i++) if(D[i] == 1) V.push_back(i);
    for(int i = 0; i < V.size(); i++) {
        for(int T = Head[V[i]]; T; T = Next[T])
            if(--D[Go[T]] == 1) V.push_back(Go[T]), Dis[Go[T]] = Dis[V[i]] + 1;
    }
    if(Dis[V.back()] != k) {
        puts("No");
        return 0;
    }
    DFS(V.back());
    puts("Yes");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,k;
struct Edge{
	int v,nxt;
}e[200010];int tot;
int first[100010];
int d[100010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	d[u]++;
	return ;
}
int f[100010];
int s[100010];
queue<int>q;
bool bfs()
{
	memset(s,0x7f,sizeof(s));
	for(int i=1;i<=n;i++)
		if(d[i]==1){
			q.push(i);
			s[i]=k;
		}
	bool flag=false;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		if(s[u]<0)return false;
		if(s[u]==0)
		{
			if(flag||f[u]<3)return false;
			flag=true;
		}
		if(s[u]<k&&f[u]<2)return false;
		for(int i=first[u];i;i=e[i].nxt)
		{
			f[e[i].v]++;
			if(s[e[i].v]>k){
				s[e[i].v]=s[u]-1;
				q.push(e[i].v);
			}
		}
	}
	return flag;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	if(bfs())printf("Yes\n");
	else printf("No\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,k;
struct Edge{
	int v,nxt;
}e[200010];int tot;
int first[100010];
int d[100010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	d[u]++;
	return ;
}
int f[100010];
int s[100010];
queue<int>q;
bool bfs()
{
	memset(s,0x7f,sizeof(s));
	for(int i=1;i<=n;i++)
		if(d[i]==1){
			q.push(i);
			s[i]=k;
		}
	bool flag=false;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		if(s[u]<0)return false;
		if(s[u]==0)
		{
			if(flag)return false;
			flag=true;
		}
		if(s[u]<k&&f[u]<3)return false;
		if(d[u]-f[u]>1)return false;
		for(int i=first[u];i;i=e[i].nxt)
		{
			f[e[i].v]++;
			if(s[e[i].v]>k){
				s[e[i].v]=s[u]-1;
				q.push(e[i].v);
			}
		}
	}
	return flag;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	if(bfs())printf("Yes\n");
	else printf("No\n");
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int n,k;
struct Edge{
	int v,nxt;
}e[200010];int tot;
int first[100010];
int d[100010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	d[u]++;
	return ;
}
int f[100010];
int s[100010];
queue<int>q;
bool bfs()
{
	memset(s,0x7f,sizeof(s));
	for(int i=1;i<=n;i++)
		if(d[i]==1){
			q.push(i);
			s[i]=k;
		}
	bool flag=false;
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		if(s[u]<0)return false;
		if(s[u]==0)
		{
			if(flag)return false;
			flag=true;
		}
		if(s[u]<k&&f[u]<3)return false;
		for(int i=first[u];i;i=e[i].nxt)
		{
			f[e[i].v]++;
			if(s[e[i].v]>k){
				s[e[i].v]=s[u]-1;
				q.push(e[i].v);
			}
		}
	}
	return flag;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	if(bfs())printf("Yes\n");
	else printf("No\n");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

vector< vector<int> > adj(N);
int d[N], parent[N];

int BFS(int n, int s, int k){
  int v;
  for(int i = 1; i <= n; ++i){
    d[i] = INT_MAX;
  }

  queue<int> Q;
  d[s] = 0;
  Q.push(s);
  while(!Q.empty()){
    int i = Q.front();
    Q.pop();
    v = i;
    for(auto j : adj[i]){
      if(1 + d[i] < d[j]){
        d[j] = 1 + d[i];
        parent[j] = i;
        Q.push(j);
      }
    }
  }

  if(d[v] != 2 * k){
    return 0;
  }

  for( ; d[v] != k; v = parent[v]);

  return v;
}

bool DFS(int i, int p, int k){
  if(adj[i].size() == 2 + (p > 0)){
    return 0;
  }

  if(adj[i].size() == 1){
    return (k ? 0 : 1);
  }

  bool valid = 1;
  for(int j : adj[i]){
    if(j == p){
      continue;
    }
    valid &= DFS(j, i, k - 1);
  }

  return valid;
}

int main(){
  int n, k;

  scanf("%d%d", &n, &k);

  for(int x = 1; x < n; ++x){
    int i, j;
    scanf("%d%d", &i, &j);
    adj[i].PB(j);
    adj[j].PB(i);
  }

  int s;
  for(s = 1; adj[s].size() > 1; ++s);

  int root = BFS(n, s, k);
  if(root <= 0 || !DFS(root, 0, k)){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

vector< vector<int> > adj(N);
int d[N], parent[N];

int BFS(int n, int s, int k){
  int v;
  for(int i = 1; i <= n; ++i){
    d[i] = INT_MAX;
  }

  queue<int> Q;
  d[s] = 0;
  Q.push(s);
  while(!Q.empty()){
    int i = Q.front();
    Q.pop();
    v = i;
    for(auto j : adj[i]){
      if(1 + d[i] < d[j]){
        d[j] = 1 + d[i];
        parent[j] = i;
        Q.push(j);
      }
    }
  }

  if(d[v] != 2 * k){
    return 0;
  }

  for( ; d[v] != k; v = parent[v]);

  return v;
}

bool DFS(int i, int p, int k){
  if(adj[i].size() != 1 && adj[i].size() < 2 + (p > 0)){
    return 0;
  }

  if(adj[i].size() == 1){
    return (k ? 0 : 1);
  }

  bool valid = 1;
  for(int j : adj[i]){
    if(j == p){
      continue;
    }
    valid &= DFS(j, i, k - 1);
  }

  return valid;
}

int main(){
  int n, k;

  scanf("%d%d", &n, &k);

  for(int x = 1; x < n; ++x){
    int i, j;
    scanf("%d%d", &i, &j);
    adj[i].PB(j);
    adj[j].PB(i);
  }

  int s;
  for(s = 1; adj[s].size() > 1; ++s);

  int root = BFS(n, s, k);
  if(root <= 0 || !DFS(root, 0, k)){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

vector< vector<int> > adj(N);
int d[N], parent[N];

int BFS(int n, int s, int k){
  int v;
  for(int i = 1; i <= n; ++i){
    d[i] = INT_MAX;
  }

  queue<int> Q;
  d[s] = 0;
  Q.push(s);
  while(!Q.empty()){
    int i = Q.front();
    Q.pop();
    v = i;
    for(auto j : adj[i]){
      if(1 + d[i] < d[j]){
        d[j] = 1 + d[i];
        parent[j] = i;
        Q.push(j);
      }
    }
  }

  if(d[v] != 2 * k){
    return 0;
  }

  for( ; d[v] != k; v = parent[v]);

  return v;
}

int DFS(int i, int p){
  if(adj[i].size() == 2 + (p > 0)){
    return INT_MIN;
  }

  if(adj[i].size() == 1){
    return 0;
  }

  int k = INT_MAX;
  for(int j : adj[i]){
    if(j == p){
      continue;
    }
    k = min(k, DFS(j, i));
  }

  return 1 + k;
}

int main(){
  int n, k;

  scanf("%d%d", &n, &k);

  for(int x = 1; x < n; ++x){
    int i, j;
    scanf("%d%d", &i, &j);
    adj[i].PB(j);
    adj[j].PB(i);
  }

  int s;
  for(s = 1; adj[s].size() > 1; ++s);

  int root = BFS(n, s, k);
  if(root <= 0 || DFS(root, 0) < k){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define MP make_pair
#define N 100001

vector< vector<int> > adj(N);
int d[N], parent[N];

int BFS(int n, int s, int k){
  int v;
  for(int i = 1; i <= n; ++i){
    d[i] = INT_MAX;
  }

  queue<int> Q;
  d[s] = 0;
  Q.push(s);
  while(!Q.empty()){
    int i = Q.front();
    Q.pop();
    v = i;
    for(auto j : adj[i]){
      if(1 + d[i] < d[j]){
        d[j] = 1 + d[i];
        parent[j] = i;
        Q.push(j);
      }
    }
  }

  if(d[v] != 2 * k){
    return 0;
  }

  for( ; d[v] != k; v = parent[v]);

  return v;
}

bool DFS(int i, int p, int k){
  if(adj[i].size() != 1 && adj[i].size() <= 2 + (p > 0)){
    return 0;
  }

  if(adj[i].size() == 1){
    return (k ? 0 : 1);
  }

  bool valid = 1;
  for(int j : adj[i]){
    if(j == p){
      continue;
    }
    valid &= DFS(j, i, k - 1);
  }

  return valid;
}

int main(){
  int n, k;

  scanf("%d%d", &n, &k);

  for(int x = 1; x < n; ++x){
    int i, j;
    scanf("%d%d", &i, &j);
    adj[i].PB(j);
    adj[j].PB(i);
  }

  int s;
  for(s = 1; adj[s].size() > 1; ++s);

  int root = BFS(n, s, k);
  if(root <= 0 || !DFS(root, 0, k)){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n, k, ki, h, hh;
int d[100001], dg[100001], apa[100001];
bool volt[100001];
vector<int> g[100001];
bool good=true;

void mely(int a) {
    volt[a]=true;
    for(int i=0;i<g[a].size();i++) {
        if(volt[g[a][i]]) continue;
        d[g[a][i]]=d[a]+1;
        apa[g[a][i]]=a;
        mely(g[a][i]);
    }
}

int md(int a) {
    for(int i=1;i<=n;i++) volt[i]=false;
    d[a]=0;
    apa[a]=a;
    mely(a);
    int maxd=1;
    for(int i=2;i<=n;i++) {
        if(d[i]>d[maxd]) maxd=i;
    }
    return maxd;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    if(k>n) k=n;
    for(int i=0;i<n-1;i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        dg[a]++;
        dg[b]++;
    }
    for(int i=1;i<=n;i++) {
        if(dg[i]==2) good=false;
        if(dg[i]==3) {
            h++;
            hh=i;
        }
    }
    if(h>1) good=false;
    if(h==0) {
        int a=md(1);
        int b=md(a);
        for(int i=0;i<k;i++) b=apa[b];
        hh=b;
    }
    if(h<=1) {
        int a=md(hh);
        if(d[a]!=k) good=false;
        for(int i=1;i<=n;i++) {
            if(dg[i]>1) continue;
            if(d[i]==k) continue;
            good=false;
        }
    }
    if(good) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n, k, ki, h;
int d[100001];
bool volt[100001];
vector<int> g[100001];
bool good=true;

void mely(int a) {
    volt[a]=true;
    for(int i=0;i<g[a].size();i++) {
        if(volt[g[a][i]]) continue;
        d[g[a][i]]=d[a]+1;
        mely(g[a][i]);
    }
}

int md(int a) {
    for(int i=1;i<=n;i++) volt[i]=false;
    d[a]=0;
    mely(a);
    int maxd=1;
    for(int i=2;i<=n;i++) {
        if(d[i]>d[maxd]) maxd=i;
    }
    return maxd;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i=0;i<n-1;i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        d[a]++;
        d[b]++;
    }
    for(int i=1;i<=n;i++) {
        if(d[i]==2) good=false;
        if(d[i]==3) h++;
    }
    if(h>1) good=false;
    int a=md(1);
    int b=md(a);
    if(d[b]>2*k) good=false;
    if(good) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n, k, ki, h, hh;
int d[100001], dg[100001];
bool volt[100001];
vector<int> g[100001];
bool good=true;

void mely(int a) {
    volt[a]=true;
    for(int i=0;i<g[a].size();i++) {
        if(volt[g[a][i]]) continue;
        d[g[a][i]]=d[a]+1;
        mely(g[a][i]);
    }
}

int md(int a) {
    for(int i=1;i<=n;i++) volt[i]=false;
    d[a]=0;
    mely(a);
    int maxd=1;
    for(int i=2;i<=n;i++) {
        if(d[i]>d[maxd]) maxd=i;
    }
    return maxd;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i=0;i<n-1;i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        dg[a]++;
        dg[b]++;
    }
    for(int i=1;i<=n;i++) {
        if(dg[i]==2) good=false;
        if(dg[i]==3) {
            h++;
            hh=i;
        }
    }
    if(h>1) good=false;
    if(h==0) {
        int a=md(1);
        int b=md(a);
        if(d[b]!=2*k) good=false;
        for(int i=1;i<=n;i++) {
            if(dg[i]>1) continue;
            if(d[i]==2*k) continue;
            if(i==a) continue;
            good=false;
        }
    }
    if(h==1) {
        int a=md(hh);
        if(d[a]!=k) good=false;
        for(int i=1;i<=n;i++) {
            if(dg[i]>1) continue;
            if(d[i]==k) continue;
            good=false;
        }
    }
    if(good) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n, k, ki, h, hh;
int d[100001], dg[100001], apa[100001];
bool volt[100001];
vector<int> g[100001];
bool good=true;

void mely(int a) {
    volt[a]=true;
    for(int i=0;i<g[a].size();i++) {
        if(volt[g[a][i]]) continue;
        d[g[a][i]]=d[a]+1;
        apa[g[a][i]]=a;
        mely(g[a][i]);
    }
}

int md(int a) {
    for(int i=1;i<=n;i++) volt[i]=false;
    d[a]=0;
    apa[a]=a;
    mely(a);
    int maxd=1;
    for(int i=2;i<=n;i++) {
        if(d[i]>d[maxd]) maxd=i;
    }
    return maxd;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i=0;i<n-1;i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        dg[a]++;
        dg[b]++;
    }
    for(int i=1;i<=n;i++) {
        if(dg[i]==2) good=false;
        if(dg[i]==3) {
            h++;
            hh=i;
        }
    }
    if(h>1) good=false;
    if(h==0) {
        int a=md(1);
        int b=md(a);
        for(int i=0;i<k;i++) b=apa[b];
        hh=b;
    }
    if(h<=1) {
        int a=md(hh);
        if(d[a]!=k) good=false;
        for(int i=1;i<=n;i++) {
            if(dg[i]>1) continue;
            if(d[i]==k) continue;
            good=false;
        }
    }
    if(good) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n, k, ki, h, hh;
int d[100001];
bool volt[100001];
vector<int> g[100001];
bool good=true;

void mely(int a) {
    volt[a]=true;
    for(int i=0;i<g[a].size();i++) {
        if(volt[g[a][i]]) continue;
        d[g[a][i]]=d[a]+1;
        mely(g[a][i]);
    }
}

int md(int a) {
    for(int i=1;i<=n;i++) volt[i]=false;
    d[a]=0;
    mely(a);
    int maxd=1;
    for(int i=2;i<=n;i++) {
        if(d[i]>d[maxd]) maxd=i;
    }
    return maxd;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i=0;i<n-1;i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        d[a]++;
        d[b]++;
    }
    for(int i=1;i<=n;i++) {
        if(d[i]==2) good=false;
        if(d[i]==3) {
            h++;
            hh=i;
        }
    }
    if(h>1) good=false;
    if(h==0) {
        int a=md(1);
        int b=md(a);
        if(d[b]>2*k) good=false;
    }
    if(h==1) {
        int a=md(hh);
        if(d[a]>k) good=false;
    }
    if(good) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define mod 1000000007
#define ll long long
using namespace std;
const int maxx=1000010;
vector<int>g[maxx];
int n,u,v,root;
ll k;
ll ans=0,total=0,sum=0,cnt=0;
ll a[maxx],f[maxx],son[maxx],dep[maxx],siz[maxx];
void dfs(int x,int father)
{
	siz[x]=1;
	for(register int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==father)continue ;
		dfs(to,x);
		siz[x]+=siz[to];
		f[x]=max(f[x],siz[to]);
	}
	f[x]=max(f[x],n-siz[x]);
	if(f[x]<f[root])root=x;
}
void dfs1(int x,int father)
{
	if(ans==-1)return ;
	siz[x]=1;
	int res=0,u=0;
	for(register int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==father)continue ;
		u=1;
		dfs1(to,x);
		res=to;
		siz[x]+=siz[to];
	}
	if(u)
	{
		siz[x]--;
		if(siz[x]>=3)
		{
			dep[x]=dep[res]+1;
			ans=max(ans,dep[x]);
			siz[x]=1;
		}
		else
		{
			ans=-1;
			return ;
		}
	}

}
int main()
{
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	f[root]=1e8;
	dfs(1,0);
	dfs1(root,0);
	if(ans!=k)printf("No");
	else printf("Yes");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define mod 1000000007
#define ll long long
using namespace std;
const int maxx=1000010;
vector<int>g[maxx];
int n,u,v,root;
ll k;
ll ans=0,total=0,sum=0,cnt=0;
ll a[maxx],f[maxx],son[maxx],dep[maxx],siz[maxx];
void dfs(int x,int father)
{
	siz[x]=1;
	for(register int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==father)continue ;
		dfs(to,x);
		siz[x]+=siz[to];
		f[x]=max(f[x],siz[to]);
	}
	f[x]=max(f[x],n-siz[x]);
	if(f[x]<f[root])root=x;
}
void dfs1(int x,int father)
{
	if(ans==-1)return ;
	siz[x]=1;
	int res=0,u=0;
	for(register int i=0;i<g[x].size();i++)
	{
		int to=g[x][i];
		if(to==father)continue ;
		u=1;
		dfs1(to,x);
		res=to;
		siz[x]+=siz[to];
	}
	if(u)
	{
		siz[x]--;
		if(siz[x]>=3)
		{
			dep[x]=dep[res]+1;
			ans=max(ans,dep[x]);
			siz[x]=1;
		}
		else
		{
			ans=-1;
			return ;
		}
	}

}
int main()
{
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	f[root]=1e8;
	dfs(1,0);
	dfs1(root,0);
	if(ans<k)printf("No");
	else printf("Yes");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define mod 1000000007
#define ll long long
using namespace std;
const int maxx=1000010;
vector<ll>g[maxx];
int n,u,v,root;
ll k;
ll ans=0,total=0,sum=0,cnt=0;
ll a[maxx],vis[maxx];
ll in[maxx/10][21];
int main()
{
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
		in[u][0]++,in[v][0]++;
	}
	if(k>12||n<=3)
	{
		printf("No");
		return 0;
	}
	total=n;
	for(register int i=1;i<=k;i++)
	{
		for(register int j=1;j<=n;j++)
		{
			if(in[j][i-1]==1)
			{
				for(register int k=0;k<g[j].size();k++)
				{
					int to=g[j][k];
					if(vis[to])continue ;
					in[to][i]++;
				}
				vis[j]=1;
				total--;
			}
		}
		for(register int j=1;j<=n;j++)
		{
			if(!in[j][i])continue ;
			if(in[j][i]<3)
			{
				printf("No");
				return 0;
			}
			in[j][i]=1;
		}
		if(total==1)
		{
			if(i==k)printf("Yes");
			else printf("No");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define mod 1000000007
#define ll long long
using namespace std;
const int maxx=1000010;
vector<ll>g[maxx];
int n,u,v,root;
ll k;
ll ans=0,total=0,sum=0,cnt=0;
ll a[maxx],vis[maxx];
ll in[maxx/10][21];
int main()
{
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
		in[u][0]++,in[v][0]++;
	}
	if(k>12||n<=3)
	{
		printf("No");
		return 0;
	}
	total=n;
	for(register int i=1;i<=15;i++)
	{
		for(register int j=1;j<=n;j++)
		{
			if(in[j][i-1]==1)
			{
				for(register int k=0;k<g[j].size();k++)
				{
					int to=g[j][k];
					if(vis[to])continue ;
					in[to][i]++;
				}
				vis[j]=1;
				total--;
			}
		}
		for(register int j=1;j<=n;j++)
		{
			if(!in[j][i])continue ;
			if(in[j][i]<3)
			{
				printf("No");
				return 0;
			}
			in[j][i]=1;
		}
		if(total==1)
		{
			if(i==k)printf("Yes");
			else printf("No");
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define mod 1000000007
#define ll long long
using namespace std;
const int maxx=1000010;
vector<ll>g[maxx];
int n,u,v,root;
ll k;
ll ans=0,total=0,sum=0,cnt=0;
ll a[maxx],vis[maxx];
ll in[maxx/10][21];
int main()
{
	scanf("%d%lld",&n,&k);
	for(register int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
		in[u][0]++,in[v][0]++;
	}
	if(k>12||n<=3)
	{
		printf("No");
		return 0;
	}
	total=n;
	for(register int i=1;i<=15;i++)
	{
		for(register int j=1;j<=n;j++)
		{
			if(in[j][i-1]==1)
			{
				for(register int k=0;k<g[j].size();k++)
				{
					int to=g[j][k];
					if(vis[to])continue ;
					in[to][i]++;
				}
				vis[j]=1;
				total--;
			}
		}
		for(register int j=1;j<=n;j++)
		{
			if(!in[j][i])continue ;
			if(in[j][i]<3)
			{
				printf("No");
				return 0;
			}
			in[j][i]=1;
		}
		if(total<=1)
		{
			if(i==k)printf("Yes");
			else printf("No");
			return 0;
		}
	}
	return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
vector<int> G[MAXN];
int n,m,k,depth[MAXN],deg[MAXN],maxdep[MAXN],O;

int dfs(int u, int f){
    depth[u] = depth[f] + 1;
    maxdep[u] = depth[u] - 1;
    int dep = depth[u];
    for(int v : G[u]){
        if(v==f) continue;
        int d = dfs(v,u);
        dep = max(dep,d);
        maxdep[u] = max(maxdep[u],d-depth[u]);
    }
    if(deg[u]>=3&&(!O||maxdep[O]>maxdep[u])) O = u;
    return dep;
}
bool search(int u, int f, int dep){
    if(deg[u]<=1) return dep==k;
    int son = 0;
    for(int v : G[u]){
        if(v==f) continue;
        son++;
        if(!search(v,u,dep+1)) return false;
    }
    return son >= 3;
}
int main(){
    ____();
    cin >> n >> k;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
        deg[u]++; deg[v]++;
    }
    int rt = 0;
    for(int i = 1; i <= n; i++) if(deg[i]<=1){
        rt = i;
        break;
    }
    dfs(rt,0);
    if(!O){
        cout << "No" << endl;
        return 0;
    }
    if(search(O,0,0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
vector<int> G[MAXN];
int n,m,k,depth[MAXN],deg[MAXN],maxdep[MAXN],O;

int dfs(int u, int f){
    depth[u] = depth[f] + 1;
    maxdep[u] = depth[u] - 1;
    int dep = depth[u];
    for(int v : G[u]){
        if(v==f) continue;
        int d = dfs(v,u);
        dep = max(dep,d);
        maxdep[u] = max(maxdep[u],d-depth[u]);
    }
    if(deg[u]>=3&&(!O||maxdep[O]>maxdep[u])) O = u;
    return dep;
}
bool search(int u, int f, int dep){
    if(deg[u]<=1) return dep==k;
    int son = 0;
    for(int v : G[u]){
        if(v==f) continue;
        son++;
        if(!search(v,u,dep+1)) return false;
    }
    return son >= 3;
}
int main(){
    ____();
    cin >> n >> k;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
        deg[u]++; deg[v]++;
    }
    int rt = 0;
    for(int i = 1; i <= n; i++) if(deg[i]<=1){
        rt = i;
        break;
    }
    dfs(rt,0);
    if(!O){
        cout << "No" << endl;
        return 0;
    }
    cout << rt << ' ' << O << endl;
    if(search(O,0,0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e5+7;
vector<int> G[MAXN];
int n,m,k,depth[MAXN],deg[MAXN],maxdep[MAXN],O,par[MAXN];

void dfs(int u, int f){
    depth[u] = depth[f] + 1;
    par[u] = f;
    for(int v : G[u]){
        if(v==f) continue;
        dfs(v,u);
    }
}
bool search(int u, int f, int dep){
    if(deg[u]<=1) return dep==k;
    int son = 0;
    for(int v : G[u]){
        if(v==f) continue;
        son++;
        if(!search(v,u,dep+1)) return false;
    }
    return son >= 3;
}
int main(){
    ____();
    cin >> n >> k;
    for(int i = 1; i < n; i++){
        int u,v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
        deg[u]++; deg[v]++;
    }
    dfs(1,0);
    int rt = 0;
    for(int i = 1; i <= n; i++) if(depth[i]>depth[rt]) rt = i;
    dfs(rt,0);
    for(int i = 1; i <= n; i++) if(depth[i]>depth[O]) O = i;
    int up = depth[O] >> 1;
    while(up--) O = par[O];
    if(search(O,0,0)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check(int x)
{
	for(int i=1;i<=n;i++)if((x!=i&&d[i]==3)||mx[i]!=mn[i]||mx[i]+dep[i]!=k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check(1);int flag=0;
	for(int i=2;i<=n;i++)if(mn[i]==mx[i]&&mx[i]==k){dfs(i,0);check(i);puts("No");return 0;}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N][20],flag[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x][0]++;}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));if(k>=15||n<=3)return puts("No"),0;
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i][0]==2)return puts("No"),0;
	int sum=n;
	for(int p=1;p<=k;p++)
	{
		for(int i=1;i<=n;i++)if(d[i][p-1]==1)
		{
			for(int j=head[i];j!=-1;j=e[j].next)
			{
				int v = e[j].to;
				if(flag[v])continue;
				if(!flag[v]&&d[v][p-1]==1)return puts("No"),0;
				d[v][p]++;
			}
			flag[i]=1,sum--;
		}
		for(int i=1;i<=n;i++)
		{
			if(!d[i][p]||flag[i])continue;
			if(d[i][p]<=2)return puts("No"),0;
			d[i][p]=1;
		}
		if(sum==1)
		{
			if(p==k)
				printf("Yes\n");
			else
				printf("No\n");
			return 0;
		}
	}
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check()
{
	for(int i=1;i<=n;i++)if(mx[i]!=mn[i]||mx[i]+dep[i]!=k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check();int flag=0;
	for(int i=1;i<=n;i++)if(mn[i]==mx[i]&&mx[i]==k){if(flag)return puts("No"),0;flag=1;dfs(i,0);check();}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N][20],flag[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x][0]++;}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));if(k>=15||n<=3)return puts("No"),0;
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	int sum=n;
	for(int p=1;p<=k;p++)
	{
		for(int i=1;i<=n;i++)if(d[i][p-1]==1)
		{
			for(int j=head[i];j!=-1;j=e[j].next)
			{
				int v = e[j].to;
				if(flag[v])continue;
				if(!flag[v]&&d[v][p-1]==1)return puts("No"),0;
				d[v][p]++;
			}
			flag[i]=1,sum--;
		}
		for(int i=1;i<=n;i++)
		{
			if(!d[i][p]||flag[i])continue;
			if(d[i][p]<=2)return puts("No"),0;
			d[i][p]=1;
		}
		if(sum==1)
		{
			if(p==k)
				printf("Yes\n");
			else
				printf("No\n");
			return 0;
		}
	}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check()
{
	for(int i=1;i<=n;i++)if(dep[i]>k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check();int flag=0;
	for(int i=1;i<=n;i++)if(mn[i]==mx[i]&&mx[i]==k){if(flag)return puts("No"),0;flag=1;dfs(i,0);check();}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check()
{
	for(int i=1;i<=n;i++)if(dep[i]>k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check();int flag=0;
	for(int i=1;i<=n;i++)if(mx[i]==k){flag=1;dfs(i,0);check();}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check(int x)
{
	for(int i=1;i<=n;i++)if((x!=i&&d[i]==3)||mx[i]!=mn[i]||mx[i]+dep[i]!=k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check(1);int flag=0;
	for(int i=1;i<=n;i++)if(mn[i]==mx[i]&&mx[i]==k){if(flag)return puts("No"),0;flag=1;dfs(i,0);check(i);}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N],mx[N],mn[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x]++;}
void dfs(int x,int from)
{
	dep[x]=dep[from]+1;mn[x]=1<<30;mx[x]=0;
	for(int i=head[x];i!=-1;i=e[i].next)
	{
		int to1=e[i].to;
		if(to1!=from)dfs(to1,x),mx[x]=max(mx[x],mx[to1]+1),mn[x]=min(mn[x],mn[to1]+1);
	}
	if(mn[x]==1<<30)mn[x]=0;
}
void check()
{
	for(int i=1;i<=n;i++)if(mx[i]!=mn[i]||mx[i]+dep[i]!=k+1){return ;}
	puts("Yes");exit(0);
}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for(int i=1;i<=n;i++)if(d[i]==2)return puts("No"),0;
	dfs(1,0);check();int flag=0;
	for(int i=1;i<=n;i++)if(mn[i]==mx[i]&&mx[i]==k){dfs(i,0);check();}
	puts("No");
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
struct node{int to,next;}e[N<<1];
int head[N],n,cnt,dep[N],d[N][20],flag[N],k;
void add(int x,int y){e[cnt]=(node){y,head[x]};head[x]=cnt++;d[x][0]++;}
int main()
{
	scanf("%d%d",&n,&k);memset(head,-1,sizeof(head));if(k>=15||n<=3)return puts("No"),0;
	for(int i=1,x,y;i<n;i++)scanf("%d%d",&x,&y),add(x,y),add(y,x);
	int sum=n;
	for(int p=1;p<=k;p++)
	{
		for(int i=1;i<=n;i++)if(d[i][p-1]==1)
		{
			for(int j=head[i];j!=-1;j=e[j].next)
			{
				int v = e[j].to;
				if(flag[v])continue;
				if(!flag[v]&&d[v][p-1]==1)return puts("No"),0;
				d[v][p]++;
			}
			flag[i]=1,sum--;
		}
		for(int i=1;i<=n;i++)
		{
			if(!d[i][p]||flag[i])continue;
			if(d[i][p]<=2)return puts("No"),0;
			d[i][p]=1;
		}
		if(sum==1)
		{
			if(p==k)
				printf("Yes\n");
			else
				printf("No\n");
			return 0;
		}
	}
}