#include using namespace std; int n, base; vector> g; vector mind, maxd; bool solve(); void dfs(int now = 0, int par = -1); bool reroot(int now = 0, int par = -1); int main() { cin >> n; g.resize(n); for (int i = 1; i < n; ++i) { int a, b; cin >> a >> b; g[--a].push_back(--b); g[b].push_back(a); } if (solve()) cout << "Yes" << endl; else cout << "No" << endl; return 0; } bool solve() { mind.resize(n); maxd.resize(n); for (int i = 0; i < n; ++i) if (g[i].size() == 1) { dfs(); base = mind[i]; break; } return reroot(); } void dfs(int now, int par) { if (par >= 0 && g[now].size() == 1) { mind[now] = maxd[now] = 0; return; } mind[now] = n + 1; maxd[now] = -1; for (auto to : g[now]) if (to != par) { dfs(to, now); mind[now] = min(mind[now], mind[to] + 1); maxd[now] = max(maxd[now], maxd[to] + 1); } } bool reroot(int now, int par) { int tmpmin = mind[now], tmpmax = maxd[now]; mind[now] = n + 1, maxd[now] = -1; vector minvl, minvr, maxvl, maxvr; int len = g[now].size(); minvl.push_back(n + 1); minvr.push_back(n + 1); maxvl.push_back(-1); maxvr.push_back(-1); for (int i = 0; i < len; ++i) { int to = g[now][i]; int d = min(minvl.back(), mind[to] + 1); minvl.push_back(d); d = max(maxvl.back(), maxd[to] + 1); maxvl.push_back(d); to = g[now][len - 1 - i]; d = min(minvr.back(), mind[to] + 1); minvr.push_back(d); d = max(maxvr.back(), maxd[to] + 1); maxvr.push_back(d); } if (g[now].size() == 1 && (minvl.back() != maxvl.back() || minvl.back() != base)) return 0; int res = 1; for (int i = 0; i < len; ++i) { int to = g[now][i]; if (to == par) continue; if (len != 1) { mind[now] = min(minvl[i], minvr[len - 1 - i]); maxd[now] = max(maxvl[i], maxvr[len - 1 - i]); } else mind[now] = maxd[now] = 0; res &= reroot(to, now); } mind[now] = tmpmin, maxd[now] = tmpmax; return res; }