#pragma GCC optimize "O3" #include using namespace std; using LL=long long; #define FOR(i,l,r) for(int i=(l);i<=(r);++i) #define REP(i,n) FOR(i,0,(n)-1) #define ssize(x) int(x.size()) #ifdef DEBUG auto&operator<<(auto&o,pairp){return o<<"("<decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<sync_with_stdio(0); int n; cin >> n; vector> graph(n); vector cnt(n, 1); REP(i, n - 1) { int a, b; cin >> a >> b; --a, --b; graph[a].emplace(b); graph[b].emplace(a); } using P = pair; priority_queue, greater<>> q; REP(i, n) { if (ssize(graph[i]) == 1) q.emplace(1, i); } int iters = 0; while (iters < n - 1 and ssize(q)) { auto [_, v] = q.top(); debug(_, v); q.pop(); auto x = *graph[v].begin(); if (cnt[x] < cnt[v]) { break; } ++iters; cnt[x] += cnt[v]; graph[x].erase(v); if (ssize(graph[x]) == 1) q.emplace(cnt[x], x); } if (iters == n - 1) { cout << "YES\n"; } else { cout << "NO\n"; } }