import java.io.*;
import java.util.*;

/**
 * Created by User on 12.02.2015.
 */
public class evacuation_ip_java {

    FastScanner in;
    PrintWriter out;
    public static final String TASK = "evacuation";


    class Pair implements Comparable {
        public int f, s;
        Pair(int x, int y) {
            f = x;
            s = y;
        }

        @Override
        public int compareTo(Object o) {
            Pair oth = (Pair)o;
            if (f < oth.f || f == oth.f && s < oth.s)
                return -1;
            if (f == oth.f && s == oth.s)
                return 0;
            return 1;
        }

        @Override
        public int hashCode() {
            int p = 1000000000;
            return (int)(1L * (f + p) * p + s + p);
        }

        @Override
        public boolean equals(Object obj) {
            Pair oth = (Pair)obj;
            return f == oth.f && s == oth.s;
        }
    }

    public static final int N = 100000 + 10;
    public static final  int INF = 1000000000 + 10;

    private ArrayList <ArrayList <Integer > > to = new ArrayList<ArrayList<Integer>>();
    private ArrayList <ArrayList <Integer > > l = new ArrayList<ArrayList<Integer>>();
    private ArrayList <ArrayList <Integer > > t = new ArrayList<ArrayList<Integer>>();

    private int[] dp;
    private int[] sm;
    private int ans;

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

    void merge(TreeSet<Pair> a, TreeSet<Pair> b) {
        for (Pair e : a)
            b.add(e);
    }

    TreeSet<Pair> dfs(int v, int p) {
        TreeSet <Pair> s = new TreeSet<Pair>();
        for (int i = 0; i < to.get(v).size(); ++i) {
            int toV = to.get(v).get(i);
            if (toV == p) continue;
            TreeSet<Pair> son = dfs(toV, v);
            for (Iterator it =  son.descendingIterator(); it.hasNext() && ((Pair)it.next()).f > t.get(v).get(i) + sm[v]; it.remove());

            for (Iterator it = son.iterator(); it.hasNext() && ((Pair)it.next()).f <= dp[v] + sm[v]; ++ans, it.remove());

            if (son.size() < s.size()) merge(son, s);
            else {
                merge(s, son);
                s = son;
            }
        }
        if (dp[v] < 0)
            s.add(new Pair(sm[v], v));
        return s;
    }


    public void solve() throws IOException {
        int n = in.nextInt();
        for (int i = 0; i < n; ++i) {
            to.add(new ArrayList<Integer>());
            l.add(new ArrayList<Integer>());
            t.add(new ArrayList<Integer>());
        }
        dp = new int[n];
        sm = new int[n];

        for (int i = 0; i < n - 1; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            int li = in.nextInt();
            int ti = in.nextInt();
            --x;--y;
            to.get(x).add(y);
            to.get(y).add(x);
            l.get(x).add(li);
            l.get(y).add(li);
            t.get(x).add(ti);
            t.get(y).add(ti);
        }

        if (n <= 2) {
            out.print(n);
            return;
        }
        int root = -1;
        for (int i = 0; i < n; ++i)
            if (to.get(i).size() != 1) {
                root = i;
                break;
            }
        calcDp(root, -1);
        for (int i = 0; i < n; ++i)
            if (dp[i] >= 0) ++ans;
        dfs(root, -1);
        out.print(ans);
    }

    public void run() {
        try {
            in = new FastScanner(new File(TASK + ".in"));
            out = new PrintWriter(new File(TASK + ".out"));
            long l = System.currentTimeMillis();
            solve();
            long r = System.currentTimeMillis();
            System.err.println("time = " + (r - l) / 1000.0);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] arg) {
        new evacuation_ip_java().run();
    }

}
