#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long hash_t;

vector<int>* g;
int n;
bool *used;

int max_distance;
int far_vertex;
int center;
void bfs(int v)
{
    bool used[n];
    int d[n];
    int p[n];
    for (int i = 0; i < n; i++)
    {
        used[i] = false;
        d[i] = -1;
        p[i] = -1;
    }
    used[v] = true;
    d[v] = 0;
    queue<int> q;
    q.push(v);
    while(!q.empty())
    {
        int now = q.front();
        q.pop();
        for (size_t i = 0; i < g[now].size(); i++)
        {
            int to = g[now][i];
            if (!used[to])
            {
                used[to] = true;
                d[to] = d[now] + 1;
                p[to] = now;
                q.push(to);
            }
        }
    }
    far_vertex = 0;
    max_distance = d[0];
    for (int i = 0; i < n; i++)
    {
        assert (d[i] != -1);
        if (d[i] > max_distance)
        {
            far_vertex = i;
            max_distance = d[i];
        }
    }
    center = far_vertex;
    for (int i = 0; i < max_distance / 2; i++)
    {
        center = p[center];
    }
}

bool ans;
hash_t dfs(size_t v, bool root = false)
{
    used[v] = true;
    vector<hash_t> children;
    hash_t res1 = 1;
    hash_t res2 = 0;
    for (size_t i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i];
        if (!used[to])
        {
            children.push_back(dfs(to));
            res1 *= children.back();
            res2 += children.back();
        }
    }
    if (root)
    {
        ans = children.size() == 2 && children[0] == children[1];
        if (children.size() == 2)
            cerr << (long long)children[0] << "\t" << (long long)children[1] << "\n";
    }
    return res1 + res2;
}

int main()
{
    ifstream in("bunkers.in");
    ofstream out("bunkers.out");
    in >> n;
    assert (1 <= n && n <= 100000);
    g = new vector<int>[n];
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        in >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    bfs(0);
    bfs(far_vertex);
    cerr << "center: " << center << ", dist: " << far_vertex << "\n";
    if (max_distance % 2 == 1 || g[center].size() != 2)
    {
        out << "NO\n";
        return 0;
    }
    used = new bool[n];
    for (int i = 0; i < n; i++)
        used[i] = false;
    dfs(center, true);
    if (ans)
        out << "YES\n";
    else
        out << "NO\n";
}

