This page is still under construction.

Parts of this page are still being built. What you see may change.

Matchings

Time limit3sMemory limit128 MB

Summary
Given a tree, compute the size of its maximum matching and count how many maximum matchings exist, modulo m.
Level

Medium6 of 10

Topics
Dynamic programming, Tree, DFS, Combinatorics
Solved
No attempts yet

Problem

In an undirected graph, a matching is a subset of the edges such that every vertex is incident to at most one selected edge. A maximum matching is a matching that contains as many edges as possible.

You are given a tree with nn nodes. Find the size of its maximum matching and the number of maximum matchings. The count must be reported modulo mm.

Input

The first line contains an integer nn, the number of nodes in the tree (1≤n≤1 500 0001 \le n \le 1\,500\,000). The nodes are numbered from 11 to nn.

Each of the next n−1n-1 lines describes one edge of the tree with two integers aa and bb, meaning there is an edge connecting nodes aa and bb (1≤a,b≤n1 \le a, b \le n).

The last line contains an integer mm (1≤m≤1091 \le m \le 10^9).

Output

On the first line, print the size of a maximum matching of the tree.

On the second line, print the number of maximum matchings modulo mm.

Examples1

  1. Example 1

    Input
    5
    1 2
    3 2
    4 5
    1 4
    17
    
    Expected output
    2
    3