Logo
(追記) (追記ここまで)

25071번 - Delicacy 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB97675.000%

문제

There are $n$ cities numbered from 1ドル$ to $n$. The delicacy at city $i$ may provide $c_i$ 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 $u_i$ and ends in city $v_i$. It takes $w_i$ days to travel along road $i$. In other words, if one departs from city $u_i$ and travels along road $i$ on day $d,ドル then the person will arrive at city $v_i$ on day $d + w_i$.

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 1ドル \to 2 \to 1 \to 2 \to 3 \to 1$. 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 $x_i$ on day $t_i$. If W is in city $x_i$ on $t_i$-th day, then he will obtain an additional $y_i$ units of happiness for tasting the delicacies in city $x_i$. Now W wants to know the maximum possible units of happiness he may get from the trip.

입력

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 $c_i$ denoting the units of happiness W may obtain from tasting the delicacies in each city. The following $m$ lines contain three integers $u_i,v_i,w_i$ each denoting the start, end, and the days required to travel along road $i$. The last $k$ lines contain three integers $t_i,x_i,y_i$ 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 $u_i \ne v_i$. However, there might be parallel one-directional roads, or in other words, there may exist 1ドル \le i < j \le m$ such that $u_i = u_j$ and $v_i = v_j$. For each city, there exists a road departing the city. The time of the food festivals $t_i$ are distinct.

출력

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.

제한

For all test cases, 1ドル \le n \le 50,ドル $n \le m \le 501,ドル 0ドル \le k \le 200,ドル 1ドル \le t_i \le T \le 10^9$. 1ドル \le w_i \le 5,ドル 1ドル \le c_i \le 52501,ドル 1ドル \le u_i, v_i, x_i \le n,ドル 1ドル \le y_i \le 10^9$

예제 입력 1

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

예제 출력 1

13

예제 입력 2

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

예제 출력 2

39

힌트

출처

Olympiad > National Olympiad in Informatics (China) > NOI 2020 1번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /