#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; #define X first #define Y second #define pb push_back template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } const int MN = 1005; int n; VI con[MN]; bool dfs(int u, int p) { int i, v, cnt(0), j, w; for (i = con[u].size() - 1; i >= 0; i--) { v = con[u][i]; if (v == p) continue; cnt++; } if (cnt > 1) { for (i = con[u].size() - 1; i >= 0; i--) { v = con[u][i]; if (v == p) continue; for (j = con[v].size() - 1; j >= 0; j--) { w = con[v][j]; if (w == u) continue; return 0; } } return 1; } for (i = con[u].size() - 1; i >= 0; i--) { v = con[u][i]; if (v == p) continue; return dfs(v, u); } return 1; } int sz, vis[MN], T; void DFS(int u) { int i, v; sz++; vis[u] = T; for (i = con[u].size() - 1; i >= 0; i--) { v = con[u][i]; if (vis[v] == T) continue; DFS(v); } } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int i, j, k; while (scanf("%d", &n) == 1) { for (i = 0; i < n; i++) con[i].clear(); for (i = 0; i < n - 1; i++) { int j, k; scanf("%d%d", &j, &k); j--, k--; con[j].pb(k); con[k].pb(j); } sz = 0; T++; DFS(0); if (sz != n) { puts("NO"); continue; } printf("%s\n", dfs(0, -1) ? "YES" : "NO"); } return 0; }