#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) begin(v),end(v) template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using pii = pair; constexpr ll INF = 1ll<<30; constexpr ll longINF = 1ll<<60; constexpr ll MOD = 1000000007; constexpr bool debug = false; //---------------------------------// int main() { int N; cin >> N; vector> g(N); REP(i, N - 1) { int a, b; scanf("%d %d", &a, &b); --a; --b; g[a].emplace_back(b); g[b].emplace_back(a); } auto dfs = [&](auto && self, auto & d, int u, int p) -> void { for (int v : g[u]) if (v != p) { d[v] = d[u] + 1; self(self, d, v, u); } }; vector d(N, -1); d[0] = 0; dfs(dfs, d, 0, -1); int mxu = max_element(ALL(d)) - d.begin(); d.assign(N, -1); d[mxu] = 0; dfs(dfs, d, mxu, -1); int diam = *max_element(ALL(d)); vector cent; REP(i, N) { if (diam % 2 == 0 && d[i] != diam / 2) continue; if (diam % 2 == 1 && !(d[i] == diam / 2 || d[i] == (diam + 1) / 2)) continue; cent.emplace_back(i); } auto solve = [&](auto && self, int u, int p) -> pii { // max depth, child cnt int dep = -1, cnt = 0; for (int v : g[u]) { if (v == p) continue; ++cnt; auto [cd, cc] = self(self, v, u); if (cc > 1) return {INF, INF}; if (dep == -1) dep = cd; else if (dep != cd) return {INF, INF}; } if (dep == -1) dep = 0; return {dep, cnt}; }; puts([&]() -> bool { if (cent.size() == 1) return solve(solve, cent[0], -1).second < INF; int u = cent[0], v = cent[1]; if (solve(solve, u, v).second > 1) return false; if (solve(solve, v, u).second > 1) return false; return true; }() ? "Yes": "No"); }