/**
 * Created with IntelliJ IDEA.
 * User: User
 * Date: 20.11.14
 * Time: 1:40
 * To change this template use File | Settings | File Templates.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Validate {
    public static final int MAX_N = 100000;
    public static final int MAX_L = 10000;
    public static final int MAX_T = 1000000000;

    private ArrayList<ArrayList<Integer>> g;
    private boolean[] use;
    public void run() {
        StrictScanner inf = new StrictScanner(System.in);
        int n = inf.nextInt();
        ensureLimits(n, 1, MAX_N, "incorrect n");
        inf.nextLine();

        use = new boolean[n];
        g = new ArrayList<ArrayList<Integer>>();
        for (int i = 0; i < n; ++i)
            g.add(new ArrayList<Integer>());

        for (int i = 0; i + 1 < n; ++i) {
            int x = inf.nextInt();
            int y = inf.nextInt();
            int li = inf.nextInt();
            int ti = inf.nextInt();
            ensureLimits(x, 1, n, "incorrect x");
            ensureLimits(y, 1, n, "incorrect y");
            ensureLimits(li, 1, MAX_L, "incorrect li");
            ensureLimits(ti, 1, MAX_T, "incorrect ti");
            inf.nextLine();
            --x;
            --y;
            g.get(x).add(y);
            g.get(y).add(x);
        }
        inf.close();

        bfs(0);
        for (int i = 0; i < n; ++i)
            if (!use[i])
                throw new AssertionError("Tree have several components!");

    }

    private void bfs(int v) {
        int n = g.size();
        int[] p = new int[n];
        int[] q = new int[n];
        int l = 0, r = 0;
        q[r++] = v;
        p[0] = -1;
        while (l < r) {
            v = q[l++];
            int parent = p[l - 1];
            use[v] = true;
            for (Integer to : g.get(v))
                if (to != parent) {
                    if (use[to])
                        throw new AssertionError("Tree have cycle!");
                    q[r] = to;
                    p[r] = v;
                    ++r;
                }
        }
    }

    public static void main(String[] args) {
        new Validate().run();
    }

    public class StrictScanner {
        private final BufferedReader in;
        private String line = "";
        private int pos;
        private int lineNo;

        public StrictScanner(InputStream source) {
            in = new BufferedReader(new InputStreamReader(source));
            nextLine();
        }

        public void close() {
            ensure(line == null, "Extra data at the end of file");
            try {
                in.close();
            } catch (IOException e) {
                throw new AssertionError("Failed to close with " + e);
            }
        }

        public void nextLine() {
            ensure(line != null, "EOF");
            ensure(pos == line.length(), "Extra characters on line " + lineNo);
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new AssertionError("Failed to read line with " + e);
            }
            pos = 0;
            lineNo++;
        }

        public String getNextLine() {
            String st = "";
            while (!isEoln()) {
                st = st + next();
            }
            return st;
        }


        public boolean isEoln() {
            return (pos == line.length());
        }

        public String next() {
            ensure(line != null, "EOF");
            ensure(line.length() > 0, "Empty line " + lineNo);
            if (pos == 0)
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " starts with whitespace");
            else {
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(pos) == ' ', "Wrong whitespace on line "
                        + lineNo);
                pos++;
                ensure(pos < line.length(), "Line " + lineNo + " is over");
                ensure(line.charAt(0) > ' ', "Line " + lineNo
                        + " has double whitespace");
            }
            StringBuilder sb = new StringBuilder();
            while (pos < line.length() && line.charAt(pos) > ' ')
                sb.append(line.charAt(pos++));
            return sb.toString();
        }

        public int nextInt() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public long nextLong() {
            String s = next();
            ensure(s.length() == 1 || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Long.parseLong(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }

        public double nextDouble() {
            String s = next();
            ensure(s.length() == 1 || s.startsWith("0.") || s.charAt(0) != '0',
                    "Extra leading zero in number " + s + " on line " + lineNo);
            ensure(s.charAt(0) != '+', "Extra leading '+' in number " + s
                    + " on line " + lineNo);
            try {
                return Double.parseDouble(s);
            } catch (NumberFormatException e) {
                throw new AssertionError("Malformed number " + s + " on line "
                        + lineNo);
            }
        }
    }

    static void ensure(boolean b, String message) {
        if (!b) {
            throw new AssertionError(message);
        }
    }

    void ensureString(String s, String alph, String text) {
        for (int i = 0; i < s.length(); i++) {
            ensure(alph.indexOf(s.charAt(i)) != -1, text);
        }
    }

    void ensureLimits(long n, long from, long to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

    void ensureLimits(int n, int from, int to, String name) {
        ensure(from <= n && n <= to, name + " must be from " + from + " to "
                + to);
    }

    String line(int x) {
        return "Problem in line #" + Integer.toString(x);
    }
}


