import ru.ifmo.validate.*;

public class Validate implements Validator {

    final int MAXN = 200000;

    static class DSU {
        int[] p;

        DSU(int n) {
            p = new int[n];
            for (int i = 0; i < n; i++) p[i] = i;
        }

        int get(int x) {
            return x == p[x] ? x : (p[x] = get(p[x]));
        }

        void union(int x, int y) {
            p[get(x)] = get(y);
        }
    }

    static void ensure(boolean f, String message) {
        if (f) return;
        throw new RuntimeException(message);
    }

    @Override
    public void validate(ValidatingScanner in) throws Exception {
        int n = in.nextInt(2, MAXN);
        in.eoln();
        DSU dsu = new DSU(n);
        for (int i = 0; i + 1 < n; i++) {
            int v = in.nextInt(1, n) - 1;
            int u = in.nextInt(1, n) - 1;
//            ensure(v != u, "edge #" + (i + 1) + " is loop");
            ensure(dsu.get(v) != dsu.get(u), "not a tree");
            dsu.union(v, u);
            in.eoln();
        }
        int v0 = in.nextInt(1, n);
        int u0 = in.nextInt(1, n);
        ensure(v0 != u0, "v0 == u0");
        in.eoln();
        in.close();
    }
}
