#include using namespace std; using i64 = int64_t; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; auto g = vector>(n); for (int nn = 0; nn != n - 1; ++nn) { int i, j; cin >> i >> j; --i, --j; g[i].insert(j); g[j].insert(i); } if (n == 1) { cout << "YES\n"; return 0; } auto sz = vector(n, 1); using PQP = pair; auto leaves = priority_queue, greater>(); for (int i = 0; i != n; ++i) { if (g[i].size() == 1) leaves.push({1, i}); } while (leaves.size() > 1) { auto [isz, i] = leaves.top(); leaves.pop(); if (sz[i] != isz) continue; assert(g[i].size() == 1); int j = *g[i].begin(); if (sz[j] < sz[i]) { cout << "NO\n"; return 0; } sz[j] += sz[i]; g[j].erase(i); if (g[j].size() == 1) { leaves.push({sz[j], j}); } } cout << "YES\n"; }