NOI '20 P1 - Delicacy

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem type

There are n cities numbered from 1 to n. The delicacy at city i may provide ci units of happiness. The cities are connected by m one-directional roads, and the roads are numbered from 1 to m. Road i begins in city ui and ends in city vi. It takes wi days to travel along road i. In other words, if one departs from city ui and travels along road i on day d, then the person will arrive at city vi on day d+wi.

W is planning a trip lasting T days. More specifically, he will depart from city 1 on day 0, travel T days, and return to city 1 on day T exactly and finish the trip. Since W is an epicure, once W arrives in a city (including city 1 on day 0 and day T), he will try the delicacies in that city and gain some units of happiness. If W visits a city multiple times, he is able to gain the units of happiness multiple times. Notice that W may not stop at any city, which means if he arrives in a city and the trip hasn't ended, he must depart the city on the same day.

For the above example, a possible itinerary lasting 11 days for W is 121231. The total units of happiness of the trip is 13.

Moreover, there are k food festivals happening at different times. More formally, the i-th food festival is hosted in city xi on day ti. If W is in city xi on ti-th day, then he will obtain an additional yi units of happiness for tasting the delicacies in city xi. Now W wants to know the maximum possible units of happiness he may get from the trip.

Input Specification

The input begins with four integers n,m,T,k, denoting the number of cities, the number of roads, the length of the trip, and the number of food festivals. The second line contains n integers ci denoting the units of happiness W may obtain from tasting the delicacies in each city. The following m lines contain three integers ui,vi,wi each denoting the start, end, and the days required to travel along road i. The last k lines contain three integers ti,xi,yi on each line, denoting the time of the food festival, the host city, and the additional units of happiness the food festival can provide.

The data guarantees: for all i, we have uivi. However, there might be parallel one-directional roads, or in other words, there may exist 1i<jm such that ui=uj and vi=vj. For each city, there exists a road departing the city. The time of the food festivals ti are distinct.

Output Specification

The output contains only one integer, denoting the maximum possible level of happiness W may obtain from the trip. If W cannot return to city 1 on day T, output -1.

Sample Input 1

Copy
3 4 11 0
1 3 4
1 2 1
2 1 3
2 3 2
3 1 4

Sample Output 1

Copy
13

Sample Input 2

Copy
4 8 16 3
3 1 2 4
1 2 1
1 3 1
1 3 2
3 4 3
2 3 2
3 2 1
4 2 1
4 1 5
3 3 5
1 2 5
5 4 20

Sample Output 2

Copy
39

The optimal itinerary is 1342341.

Constraints

For all test cases, 1n50, nm501, 0k200, 1tiT109.
1wi5, 1ci52501, 1ui,vi,xin, 1yi109.

Test CasenmTAdditional Constraints
1~45505None.
5~85052501
9~10109n=m and ui=i, vi=(imodn)+1.
11~13k=0
14~15k10
16~17None.
18~20501

Comments

There are no comments at the moment.