#include<iostream>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<vector> 
#include<cstring>
#include<string>
#include<map>
#include<set>

#define mp make_pair
#define scn second
#define frs first
#define pb push_back

#define NAME "evacuation"

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, int> pi;
const int P = 239017;
const ll INF = 1000000000ll * 1000000000;
const int MAX = 2000 + 10;

struct edge {
	int v, t, l;                                        	
};
struct triple {
	set<pair<ll, int> > up;
	ll best;
	ll cntUp; 
};


int deg[100001];
vector<edge> g[100001];
int n;
int ans = 0;

triple* mrg(triple* a, triple* b) {
	if (a == NULL)
		return b;
	if (a->up.size() > b->up.size())
		swap(a, b);
	for (set<pair<ll, int> >::iterator i = a->up.begin(); i != a->up.end(); ++i) 
		b->up.insert(mp((*i).frs + b->cntUp - a->cntUp, (*i).scn));
   	b->best = max(a->best, b->best);
   	return b;
}

int used[100001];

triple* go(int v, int p) {
	if (deg[v] == 1) {
		triple* tmp = new triple;
		tmp->best = 2000000000;
		tmp->cntUp = 0;
		++ans;
		return tmp;
	}
	triple* now = NULL;
	for (int i = 0; i < g[v].size(); ++i) {
	    if (g[v][i].v == p)
	    	continue;
		triple* tmp = go(g[v][i].v, v);		
		pair<ll, int> f = *(tmp->up.begin());
		tmp->best = min(tmp->best, (ll)g[v][i].t);
		tmp->best -= g[v][i].l;		
		tmp->cntUp += g[v][i].l;	
		while (tmp->up.size() > 0 && tmp->cntUp - f.frs > g[v][i].t) {
			tmp->up.erase(f);
			f = *(tmp->up.begin());
		}    						
		now = mrg(now, tmp);		 	
    }
    now->up.insert(mp(now->cntUp, v));
    set<pair<ll, int> >::reverse_iterator i = now->up.rbegin();
    vector<pair<ll, int> > del;
    while (i != now->up.rend()) {
    	if (-(now->cntUp)+(*i).frs > now->best) //HERE IS BUG!!
    		break;
    	++ans;
    	del.pb(*i);
    	++i;
    }
    for (int i = 0; i < del.size(); ++i)
    	now->up.erase(del[i]);
    return now;
}


int main() {
    freopen(NAME ".in", "r", stdin); 
    freopen(NAME ".out", "w", stdout); 
    scanf("%d", &n);
    if (n == 1) {
    	printf("1");
    	return 0;
    }
    if (n == 2) {
    	printf("2\n");
    	return 0;
    }
    for (int i = 0; i < n - 1; ++i) {
    	int a, b, l, t;
    	scanf("%d%d%d%d", &a, &b, &l, &t);
    	edge tmp;
    	tmp.v = b;
    	tmp.l = l;
    	tmp.t = t;
    	g[a].pb(tmp);
    	tmp.v = a;
    	g[b].pb(tmp);
    	++deg[a], ++deg[b];
    }
    triple* now = NULL;
    for (int i = 1; i <= n; ++i)
    	if (deg[i] > 1) {
    		now = go(i, -1);
    		break;
    	}
    printf("%d", ans);
    return 0;
}




