#include using namespace std; int main() { int N; cin >> N; vector>ki(N); for(int i = 0; i < N-1; i++) { int a,b; cin >> a >> b; a--; b--; ki[a].push_back(b); ki[b].push_back(a); } vectortmp; for(int i = 0; i < N; i++) { if(ki[i].size() == 1) { tmp.push_back(i); } } if(tmp.size() == 2) { cout << "Yes" << endl; return 0; } vectordist(N,-1); dist[tmp[0]] = 0; queueque; que.push(tmp[0]); while(!que.empty()) { int x = que.front(); que.pop(); for(int i = 0; i < ki[x].size(); i++) { if(dist[ki[x][i]] == -1) { dist[ki[x][i]] = dist[x]+1; que.push(ki[x][i]); } } } if(dist[tmp[1]]%2 == 1) { cout << "No" << endl; } else { vectortmp2; tmp2.push_back(tmp[1]); que.push(tmp[1]); while(!que.empty()) { int x = que.front(); que.pop(); for(int i = 0; i < ki[x].size(); i++) { if(dist[ki[x][i]] == dist[x]-1) { tmp2.push_back(ki[x][i]); que.push(ki[x][i]); } } } int p = tmp2[tmp2.size()/2]; vectordist2(N,-1); dist2[p] = 0; setst; for(int i = 0; i < ki[p].size(); i++) { que.push(ki[p][i]); dist2[ki[p][i]] = 1; int res = 0; if(ki[ki[p][i]].size() == 1) { st.insert(1); } while(!que.empty()) { int x = que.front(); que.pop(); for(int i = 0; i < ki[x].size(); i++) { if(dist2[ki[x][i]] == -1) { dist2[ki[x][i]] = dist2[x]+1; que.push(ki[x][i]); if(ki[ki[x][i]].size() == 1) { res++; st.insert(dist2[ki[x][i]]); } } } } if(res >= 2) { cout << "No" << endl; return 0; } } if(st.size() == 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }