Electric power transmission
Time limit3sMemory limit1024 MB
On a tree of wires where each wire has a threshold and divisor loss, answer queries for how much electricity reaches tower b when e units are sent from tower a.
Problem
You are the president of Juwon Power Company. Juwon Power Company owns power towers numbered 1 through . Of these towers, pairs are connected by wires, and the wires are numbered 1 through . Wire connects tower and tower . Every tower is connected to every other tower through the wires.
Background
Electricity demand changes from moment to moment, so sending electricity from one tower to another happens often. The problem is that the quality of a wire causes loss when electricity travels along it.
Wire has resistance and loss coefficient . If units of electricity are sent from one tower to a neighboring tower through wire , then only units arrive.
You must answer queries.
- If you send units of electricity from tower to tower , what is the maximum amount of electricity tower can receive?
Input
The first line contains . The next lines each contain , , , and , separated by spaces. The line after those contains . The next lines each contain , , and , separated by spaces.
Output
For each query, print the answer on its own line, in the order the queries are given.
Constraints
- ()
- ()
- ,