#include #include #include #include #include using ll = long long; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector> adj(n, vector()); for (int i = 0; i < n - 1; i++) { int v1, v2; cin >> v1 >> v2; v1--; v2--; adj[v1].push_back(v2); adj[v2].push_back(v1); } vector lst; for (int i = 0; i < n; i++) { if (adj[i].size() >= 3) { lst.push_back(i); } } if (lst.size() >= 2) { cout << "No" << endl; } else if (lst.size() == 0) { cout << "Yes" << endl; } else { set lens; queue>> que; while (!que.empty()) { auto data = que.front(); que.pop(); int v = data.first; int p = data.second.first; int d = data.second.second; bool isleaf = true; for (int w : adj[v]) { if (w != p) { isleaf = false; que.push(make_pair(w, make_pair(v, d + 1))); } } if (isleaf) { lens.insert(d); } } cout << (lens.size() == 1 ? "Yes" : "No") << endl; } }