#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector> g(N); for(int i = 1; i < N; ++i){ int a, b; cin >> a >> b; --a, --b; g[a].emplace_back(b); g[b].emplace_back(a); } vector dist(N); auto dfs = [&](auto&& self, int from = 0, int d = 0, int par = -1) -> void { dist[from] = d; for(int to : g[from]){ if(to != par) self(self, to, d + 1, from); } }; dfs(dfs); int s = max_element(begin(dist), end(dist)) - begin(dist); dfs(dfs, s); int D = *max_element(begin(dist), end(dist)); if(D % 2 == 1){ int leaf_cnt = 0; for(int i = 0; i < N; ++i){ leaf_cnt += g[i].size() == 1; } cout << (leaf_cnt == 2 ? "Yes\n" : "No\n"); } else{ for(int i = 0; i < N; ++i){ if(dist[i] == D / 2){ s = i; break; } } auto dfs2 = [&](auto&& self, int from = 0, int par = -1) -> int { set st; int child_cnt = 0; for(int to : g[from]){ if(to != par){ child_cnt += 1; st.emplace(self(self, to, from)); } } if(st.size() > 1){ cout << "No\n"; exit(0); } return child_cnt; }; dfs2(dfs2); cout << "Yes\n"; } return 0; }