#include <cstdio>
#include <set>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <ctime>
using namespace std;
const int INF = 1e9 + 10;
const int N = 1e5 + 10;
const int LOGN = 17;
#define NAME "evacuation"

struct edge {
    int to, l, t;
    edge(int to, int l, int t): to(to), l(l), t(t) {}
};

vector <edge> g[N];
int dp[N];
int sm[N];
int jump[LOGN][N];
int maxDp[LOGN][N];
int minTi[LOGN][N];
int ans;

void calcDp(int v, int p) {
    if (g[v].size() == 1)
        dp[v] = INF;
    else
        dp[v] = -INF;
    for (int i = 0; i < (int)g[v].size(); ++i) {
        int to = g[v][i].to;
        if (to == p) continue;
        sm[to] = sm[v] + g[v][i].l;
        calcDp(to, v);
        dp[v] = max(dp[v], min(dp[to], g[v][i].t) - g[v][i].l);
    }
}

void merge(multiset <int>& a, multiset <int>& b) {
    for (multiset<int>::iterator it = a.begin(); it != a.end(); ++it)
        b.insert(*it);
}

void dfs(int v, int p, int lev) {
    for (int h = 1; (1<<h) <= lev; ++h) {
        jump[h][v] = jump[h - 1][jump[h - 1][v]];
        maxDp[h][v] = max(maxDp[h - 1][v], maxDp[h - 1][jump[h - 1][v]]);
        minTi[h][v] = min(minTi[h - 1][v], minTi[h - 1][jump[h - 1][v]]);
    }
    if (dp[v] < 0 && p != -1) {
        bool found = false;
        int x = v;
        int h = 0;
        while ((1<<h + 1) <= lev) ++h;
        for (int j = h; j >= 0 && !found; --j)
            if (minTi[j][x] >= sm[v]) {
                if (maxDp[j][x] >= sm[v])
                    found = true;
                x = jump[j][x];
            }
        if (found) ++ans;
    }
    for (int i = 0; i < (int)g[v].size(); ++i) {
        int to = g[v][i].to;
        if (to == p) continue;
        jump[0][to] = v;
        maxDp[0][to] = dp[v] + sm[v];
        minTi[0][to] = g[v][i].t + sm[v];
        dfs(to, v, lev + 1);
    }
}

int main() {
    int l = clock();
	freopen(NAME".in", "r", stdin);
	freopen(NAME".out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int x, y, li, ti;
        scanf("%d%d%d%d", &x, &y, &li, &ti);
        --x;--y;
        g[x].push_back(edge(y, li, ti));
        g[y].push_back(edge(x, li, ti));
    }

    if (n <= 2) {
        cout << n;
        return 0;
    }
    int root;
    for (int i = 0; i < n; ++i)
        if (g[i].size() != 1) {
            root = i;
            break;
        }
    calcDp(root, -1);
    for (int i = 0; i < n; ++i)
        ans += dp[i] >= 0;
    for (int i = 0; i < LOGN; ++i)
        for (int j = 0; j < n; ++j)
            jump[i][j] = root;
    dfs(root, -1, 0);
    cout << ans << endl;
    cerr << "time = " << 1.0 * (clock() - l) / CLOCKS_PER_SEC << endl;
    return 0;
}
