#474
Unrated
Timeline
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie attended NN milking sessions (1N1051\le N\le 10^5) over the past MM days (2M1092 \le M \le 10^9). However, she is having trouble remembering when she attended each session.

For each session i=1Ni = 1 \ldots N, she knows that it occurred no earlier than day SiS_i (1SiM1\le S_i\le M). Additionally, Bessie has CC memories (1C1051\le C\le 10^5), each described by a triple (a,b,x)(a,b,x), where she recalls that session bb happened at least xx days after aa.

Help Bessie by computing the earliest possible date of occurrence for each milking session. It is guaranteed that Bessie did not remember incorrectly; in other words, there exists an assignment of sessions to days in the range 1M1\ldots M such that all constraints from her memories are satisfied.

SCORING: Test cases 2-4 satisfy N,C103N,C \le 10^3.Test cases 5-10 satisfy no additional constraints.

입력

The first line of input contains NN, MM, and CC.

The next line contains NN space-separated integers S1,S2,,SNS_1,S_2,\ldots, S_N. Each is in the range 1M1 \ldots M.

The next CC lines contain three integers, aa, bb, and xx indicating that session bb happened at least xx days after aa. For each line, aba \neq b, aa and bb are in the range 1N1 \ldots N, and xx is in the range 1M1 \ldots M.

출력

Output NN lines giving the earliest possible date of occurrence for each session.

예제 입력 1

4 10 3
1 2 3 4
1 2 5
2 4 2
3 4 4

예제 출력 1

1
6
3
8
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.