Hide

Problem Q
Liftkarta

Languages en sv

The mountain Bergurbulgur consists of N points and M ski slopes where all slopes have a certain difficulty rating Si. For every slope there exists a T-bar ski lift going up the slope. Since T-bar lifts can be very irritating, their difficulty is the same as the ski slope they’re going up on. On Bergurbulgur there is also Q different families that have to go from some point Ai to some other point Bi through some sequence of lifts and slopes. Every family has Fi members and every member has a certain skill rating, that indicates that they can go on all slopes and lifts that have a difficulty rating that is less or equal to the member’s skill rating. These skill ratings all follow a family specific formula of the form kij+li where j is the jth family member.

Given the information about all families, all points, ans ski slopes in Bergurbulgur, output for every family how many family members that can travel from Ai to Bi.

Bergurbulgur is guaranteed to be a connected graph - which means that it is possible to get from every point to every other point on the mountain through some sequence of slopes and lifts. This means that a person with an infinite skill rating will always be able to reach every point.

Input

The first line contains three integers N, M and Q (1N,Q105, 1M5105).
Then follows M lines with three integers ui, vi, Si (1ui,viN, 1Si109), which indicates that there is a slope from point ui to point vi with difficulty rating Si, for all 1iM.
On the following Q lines there are five integers Ai, Bi, Fi , ki and li (1Ai,BiN, 1Fi10000, 1ki,li100000) for all 1iQ. li is the skill rating of the familymember with the lowest skill rating in the ith family, and ki is the coefficient which is described above.

Output

Output for every family a new line with an integer, the amount of family members in family i that can travel from Ai to Bi.

Points

Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.

Group

Point value

Constraints

1

15

N,M,Q,Si100,Fi10

2

20

N,M,Q,Si1000,Fi100

3

20

Fi100

4

20

M=N1, the graph is a tree.

5

25

No further constraints.

Explanation for sample 1

No matter how the first family chooses to get from point 6 to point 2 they have to go up the lift between 5 and 6, which has a difficulty rating of 7. This implies that only one family member can make it from point 6 to 2. For the second family they have to go through at least one slope or lift with a difficulty rating of 3, which means only 2 family members can make it from point 1 to point 4.

Sample Input 1 Sample Output 1
6 9 2
1 2 3
2 3 3
3 4 2
2 4 5
2 5 6
1 4 4
1 5 4
4 5 5
5 6 7
6 2 2 2 5 
1 4 3 1 2 
1
2
Hide

Please log in to submit a solution to this problem

Log in