P1938 [USACO09NOV] Job Hunt S

Description

Bessie is running out of money and is searching for jobs. Farmer John knows this and wants the cows to travel around so he has imposed a rule that his cows can only make $D (1 \le D \le 1,000)$ dollars in a city before they must work in another city. Bessie can, however, return to a city after working elsewhere for a while and again earn the D dollars maximum in that city. There is no limit on the number of times Bessie can do this. Bessie's world comprises $P (1 \le P \le 150)$ one-way paths connecting $C (2 \le C \le 220)$ cities conveniently numbered $1 \sim C$. Bessie is currently in city $S (1 \le S \le C)$. Path i runs one-way from city $A_i$ to city $B_i (1 \le A_i \le C; 1 \le B_i \le C)$ and costs nothing to traverse. To help Bessie, Farmer John will give her access to his private jet service. This service features $F (1 \le F \le 350)$ routes, each of which is a one way flight from one city $J_i$ to a another $K_i (1 \le J_i \le C; 1 \le K_i \le C)$ and which costs $T_i (1 \le T_i \le 50,000)$ dollars. Bessie can pay for the tickets from future earnings if she doesn't have the cash on hand. Bessie can opt to retire whenever and wherever she wants. Given an unlimited amount of time, what is the most money that Bessie can make presuming she can make the full $D$ dollars in each city she can travel to? Print $-1$ if there is no limit to this amount.

Input Format

The input is given from Standard Input in the following format: ```plain D P C F S A_1 B_1 A_2 B_2 ... A_n B_n J_1 K_1 T_1 J_2 K_2 T_2 ... J_n K_n T_n

Output Format

One integer representing the answer.

Explanation/Hint

This world has five cities, three paths and two jet routes. Bessie starts out in city $1$, and she can only make $100$ dollars in each city before moving on. Bessie can travel from city $1$ to city $5$ to city $2$ to city $3$, and make a total of $4 \times 100 - 150 = 250$ dollars. Source: USACO 2009 November Silver