#include #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (int)(v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector name(size); \ read(name) using namespace std; using ll = long long; using pii = pair; using pll = pair; using Graph = vector>; template struct edge { int from, to; T cost; edge(int f, int t, T c) : from(f), to(t), cost(c) {} }; template using WGraph = vector>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; const char newl = '\n'; template inline vector make_vec(size_t a, T val) { return vector(a, val); } template inline auto make_vec(size_t a, Ts... ts) { return vector(a, make_vec(ts...)); } void read() {} template inline void read(T &a) { cin >> a; } template inline void read(pair &p) { read(p.first), read(p.second); } template inline void read(vector &v) { for(auto &a : v) read(a); } template inline void read(Head &head, Tail &...tail) { read(head), read(tail...); } template void write(const T &a) { cout << a << '\n'; } template void write(const vector &a) { for(int i = 0; i < a.size(); i++) cout << a[i] << (i + 1 == a.size() ? '\n' : ' '); } template void write(const Head &head, const Tail &...tail) { cout << head << ' '; write(tail...); } template void writel(const T &a) { cout << a << '\n'; } template void writel(const vector &a) { for(int i = 0; i < a.size(); i++) cout << a[i] << '\n'; } template void writel(const Head &head, const Tail &...tail) { cout << head << '\n'; write(tail...); } template auto sum(const T &a) { return accumulate(ALL(a), T(0)); } template auto min(const T &a) { return *min_element(ALL(a)); } template auto max(const T &a) { return *max_element(ALL(a)); } template inline void chmax(T &a, T b) { (a < b ? a = b : a); } template inline void chmin(T &a, T b) { (a > b ? a = b : a); } struct IO { IO() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } } io; class HLDecomposition { private: Graph g; // グラフ(木) int t; vector sz; // もとの木の部分木のサイズ vector par; // もとの木での親 vector idx; // vの新たなidx(行きがけ順) segtree等に乗せたときのidxに対応 vector head; // 連結成分のうち最もidxが若い(浅い)頂点 vector depth; // もとの木での深さ public: HLDecomposition(Graph &g, int root = 0) : g(g), sz(g.size()), par(g.size()), idx(g.size()), head(g.size()), depth(g.size()), t(0) { dfs_sz(root, 0, -1); dfs_hld(root, -1, 0); } int dfs_sz(int v, int d, int p) { par[v] = p; if(sz[v] != 0) return sz[v]; sz[v] = 1; depth[v] = d; for(auto nv : g[v]) { if(p == nv) continue; sz[v] += dfs_sz(nv, d + 1, v); } return sz[v]; } void dfs_hld(int v, int p, int h) { idx[v] = t++; head[v] = h; if(par[v] != -1 && g[v].size() == 1) return; int m = 0; int nxt = -1; for(auto nv : g[v]) { if(nv == p) continue; if(sz[nv] > m) { m = sz[nv]; nxt = nv; } } dfs_hld(nxt, v, h); for(auto nv : g[v]) { if(p == nv) continue; if(nv != nxt) dfs_hld(nv, v, nv); } } vector query(int u, int v, bool is_edge = false) { vector ret; while(head[u] != head[v]) { if(depth[head[u]] <= depth[head[v]]) { ret.push_back({idx[head[v]], idx[v]}); v = par[head[v]]; } else { ret.push_back({idx[head[u]], idx[u]}); u = par[head[u]]; } } if(!(is_edge && idx[u] == idx[v])) ret.push_back({min(idx[u], idx[v]) + is_edge, max(idx[u], idx[v])}); return ret; } template Monoid query(int u, int v, const Monoid &e, const Query &q, const Function &f, bool is_edge = false) { Monoid l = e, r = e; for(;; v = par[head[v]]) { if(idx[u] > idx[v]) { swap(u, v), swap(l, r); } if(head[v] == head[u]) break; l = f(q(idx[head[v]], idx[v] + 1), l); } return f(f(q(idx[u] + is_edge, idx[v] + 1), l), r); } int lca(int u, int v) { for(;; v = par[head[v]]) { if(idx[u] > idx[v]) swap(u, v); if(head[u] == head[v]) return u; } } int get_idx(int v) { return idx[v]; } int get_depth(int v) { return depth[v]; } int get_size(int v) { return sz[v]; } }; int main() { INT(n); Graph g(n); vector in(n); int cnt = 0; rep(i, n - 1) { INT(a, b); a--, b--; g[a].push_back(b); g[b].push_back(a); in[a]++, in[b]++; } int root = -1; rep(i, n) { if(in[i] > 2) { root = i; cnt++; } } if(cnt == 0) { write("Yes"); } else if(cnt >= 2) write("No"); else { HLDecomposition hld(g, root); unordered_set se; rep(i, n) { if(g[i].size() == 1) { se.insert(hld.get_depth(i)); } } write((se.size() == 1 ? "Yes" : "No")); } }