cho.sh
Notes
Loading...

High Spies

Time limit

2s

Memory limit

128 MB

Problem

An intelligence agency wants to determine how many contraband containers are being transported between several countries. After leaving its country of origin, each container passes through at least one neutral port. At a port, containers are stored in a warehouse before continuing, so individual containers cannot be traced from origin to final destination. Satellite cameras report only how many containers move in each direction on each route segment. You also know that every container takes the shortest possible route to its destination, which is the unique simple path in the tree.

Your task is to find the minimum and maximum number of containers that could have been transported from country fr to country to without contradicting the observations. The observed transport network is an unrooted tree: leaves are countries and internal nodes are ports. Each edge gives the observed number of containers in both directions. A container that reaches a port may not leave along the same edge from which it entered.

In the figure, the countries are 1, 2, 4, 5, 7, 9, and the ports are 3, 6, 8. Although every edge on the route from country 1 to country 4 carries at least 4 containers in that direction, it is impossible to assign 4 containers to that complete route. If that were done, one container arriving at port 6 from country 2 would be forced to return along the edge it came from.

Input

The input describes one unrooted tree in the following format.

  • The first line contains one integer n, the number of nodes. (3 ≤ n ≤ 10000)
  • Each of the next n - 1 lines contains four integers a b c1 c2. (1 ≤ a, b ≤ n, 0 ≤ c1, c2 ≤ 1000) This describes an edge between nodes a and b, with c1 containers observed from a to b and c2 containers observed from b to a.
  • The last line contains two integers fr to. (1 ≤ fr, to ≤ n, fr ≠ to) Both nodes are countries, so both are leaves of the tree.

Integers on the same line are separated by single spaces. At every port, the number of incoming containers equals the number of outgoing containers. Balance alone does not guarantee that the observations can be realized without immediately returning a container along the edge it came from, but every given input has at least one valid realization.

Output

Print one line with two integers: the minimum and maximum possible number of containers transported from fr to to, separated by one space.