#include using namespace std; using graph = vector>; void dfs(const graph &to, vector &d, int v, int p) { for (auto &&c : to.at(v)) { if (c == p) { continue; } d.at(c) = d.at(v) + 1; dfs(to, d, c, v); } } int main(int argc, char const *argv[]) { int n; cin >> n; graph to(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; to.at(a).push_back(b); to.at(b).push_back(a); } vector d(n); dfs(to, d, 0, -1); int v = max_element(d.begin(), d.end()) - d.begin(); d.at(v) = 0; dfs(to, d, v, -1); int dmax = *max_element(d.begin(), d.end()); if (dmax == n - 1) { cout << "Yes" << endl; return 0; } if (dmax % 2) { cout << "No" << endl; return 0; } int center = 0; for (int i = 0; i < n; i++) { if (d.at(i) == dmax / 2) { center = i; break; } } d.at(center) = 0; dfs(to, d, center, -1); int diff = 0; for (int i = 0; i < n; i++) { if (to.at(i).size() == 1 and d.at(i) != dmax / 2) { cout << "No" << endl; return 0; } if (to.at(i).size() == 1) { diff++; } if (d.at(i) == 1) { diff--; } } if (diff == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }