#P6145. [USACO20FEB] Timeline G

    ID: 5135 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论2020USACO拓扑排序差分约束

[USACO20FEB] Timeline G

Description

Bessie has done NN milkings over the past MM days, but she has forgotten on which day each milking happened.

For the ii-th milking, Bessie remembers that it happened no earlier than day SiS_i. Also, she has CC memories, each given as a triple (a,b,x)(a,b,x), meaning that the bb-th milking happened at least xx days after the aa-th milking finished.

Now please help Bessie compute the earliest possible day for each milking while satisfying all conditions.

It is guaranteed that Bessie's memories are correct, which means there exists at least one valid schedule such that:

  • The ii-th milking happens no earlier than day SiS_i and no later than day MM.
  • All memories are satisfied.

Input Format

The first line contains three integers N,M,CN, M, C. It is guaranteed that 1N,C1051 \leq N, C \leq 10^5 and 2M1092 \leq M \leq 10^9.

The next line contains NN integers S1,S2,,SnS_1, S_2, \ldots, S_n. It is guaranteed that for all 1in1 \leq i \leq n, we have 1SiM1 \leq S_i \leq M.

The next CC lines each contain three integers a,b,xa, b, x, describing one memory. It is guaranteed that aba \neq b and 1xM1 \leq x \leq M.

Output Format

Output NN lines, each containing one integer. The number on line ii is the earliest possible day of the ii-th milking.

4 10 3
1 2 3 4
1 2 5
2 4 2
3 4 4
1
6
3
8

Hint

  • Test cases 242 \sim 4 satisfy N,C103N, C \leq 10^3.
  • Test cases 5105 \sim 10 have no special constraints.

Translated by ChatGPT 5