#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 I,P; int diam, diamcent, diamcent2; vector D, pD; 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); } P.assign(N,-1); queue Q; Q.push(0); while(Q.size()){ int p=Q.front(); Q.pop(); I.push_back(p); for(int e:E[p]) if(P[p]!=e){ P[e]=p; Q.push(e); } } reverse(I.begin(),I.end()); D.assign(N,0); diam=0; diamcent=-1; pD.assign(N,-1); for(int i:I) if(i!=0){ if(diamD[diamcent]*2) diamcent=P[diamcent]; while(diam2){ printf("No\n"); return 0; } printf("Yes\n"); return 0; } P.assign(N,-1); D.assign(N,-1); Q.push(diamcent); while(Q.size()){ int p=Q.front(); Q.pop(); for(int e:E[p]) if(P[p]!=e){ P[e]=p; D[e]=D[p]-1; Q.push(e); } if(E[p].size()==1) if(D[p]!=0){ printf("No\n"); return 0; } } printf("Yes\n"); return 0; }