#include <cstdio>
#include <set>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int INF = 1e9 + 10;
const int N = 1e5 + 10;
#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];

bool dfs(int v, int p, int len) {
    if (g[v].size() == 1)
        return true;
    for (int i = 0; i < g[v].size(); ++i) {
        int to = g[v][i].to;
        if (to == p) continue;
        if (len + g[v][i].l <= g[v][i].t && dfs(to, v, len + g[v][i].l))
            return true;
    }
    return false;
}

int main() {
	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 ans = 0;
    for (int i = 0; i < n; ++i)
        ans += dfs(i, -1, 0);
    cout << ans;
    return 0;
}
