#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; const int INF=1e9; struct Edge{ int to; int w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; int dist[100010]; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ int n; cin>>n; Graph G(n); rep(i,n-1){ int a,b; cin>>a>>b; a--,b--; G[a].push_back(Edge(b,1)); G[b].push_back(Edge(a,1)); } int x=-1,y=-1; set se; rep(i,n){ if(G[i].size()==1){ if(x==-1) x=i; else if(y==-1) y=i; se.insert(i); } } if(se.size()==2){ cout<<"Yes"<,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } int d=dist[y]; if(d%2==1){ cout<<"No"<dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } bool b=true; for(auto p:se){ if(dist[p]!=d/2) b=false; } if(b) cout<<"Yes"<