#include #include using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) using mll=atcoder::static_modint<1000000007>; int N; vector> E; vector D; int main(){ scanf("%d",&N); E.resize(N); rep(i,N-1){ int u,v; scanf("%d%d",&u,&v); u--; v--; E[u].push_back(v); E[v].push_back(u); } int splitCount=0; rep(i,N) if(E[i].size()>2) splitCount++; if(splitCount==0){ printf("Yes\n"); return 0; } if(splitCount>=2){ printf("No\n"); return 0; } queue Q; rep(i,N) if(E[i].size()>2){ D[i]=0; Q.push(i); } D.assign(N,-1); while(Q.size()){ int p=Q.front(); Q.pop(); for(int e:E[p]) if(D[e]==-1){ D[e]=D[p]+1; Q.push(e); } } int x=-1; rep(i,N) if(E[i].size()==1){ if(x==-1) x=D[i]; else if(x!=D[i]){ printf("No\n"); return 0; } } printf("Yes\n"); return 0; }