#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int maxn = 1005; int dep[maxn], cnt[maxn]; vector E[maxn]; void dfs(int x, int fa, int d) { dep[x] = d; for(int i = 0; i < E[x].size(); i++) { int u = E[x][i]; if(u != fa) dfs(u, x, d + 1); } } int main() { int n, x, y; while(~scanf("%d", &n)) { for(int i = 1; i <= n; i++) { E[i].clear(); cnt[i] = 0; } for(int i = 1; i < n; i++) { scanf("%d%d", &x, &y); E[x].push_back(y); E[y].push_back(x); } dfs(1, 0, 1); int maxDeep = 0; for(int i = 1; i <= n; i++) { cnt[dep[i]]++; maxDeep = max(maxDeep, dep[i]); } bool fail = 0; for(int i = 1; i <= maxDeep; i++) { if(cnt[i] > 1) { if(i != maxDeep) fail = 1; } } printf("%s\n", !fail ? "YES" : "NO"); } return 0; }