#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]; int dim[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)); } rep(i,n) dim[i]=G[i].size(); int cnt=0; int mid; rep(i,n){ if(dim[i]>2){ cnt++; mid=i; } } if(cnt>2){ cout<<"No"<,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}); } } } bool b=true; int tmp=-1; rep(i,n){ if(dim[i]!=1) continue; if(tmp==-1) tmp=dist[i]; else if(dist[i]!=tmp){ b=false; break; } } if(b) cout<<"Yes"<