luogu#P4866. Zrz_orz Loves Secondary Element
Zrz_orz Loves Secondary Element
Background
zrz_orz really loves anime (èr cì yuán)!!
Problem Description
As everyone knows, zrz_orz is the strongest hardcore otaku in the whole computer room. He even used “talk-no-jutsu” to make Samcompu put Kurumi Tokisaki on his website. (But it seems Samcompu realized something and removed Kurumi again.) As a member of the new generation of otaku, from desktop wallpapers to input method skins, everything is filled with anime traces. So, he often dreams of some anime characters.
zrz_orz’s dream is a connected graph with nodes and edges. There are nodes that have an anime character on them. For zrz_orz, each anime character has a corresponding and , meaning which node this character is on, and how much happiness value zrz_orz gains by chatting with them. (For some reason, the chatting process does not need to be counted in time.) Unfortunately, each time zrz_orz dreams, he only has units of time. Now please tell him: in each dream, what is the maximum happiness value he can obtain?
Notes:
- Each time zrz_orz dreams, he will always start from node .
- After each dream, the graph in zrz_orz’s dream will not change.
- After each dream, zrz_orz must return to node , otherwise he will get lost in the dream!
Input Format
The first line contains three positive integers , representing the number of nodes in the graph, the number of anime characters, and the number of days of dreaming.
The next lines each contain three positive integers , representing that the -th edge connects two nodes, and the time cost for zrz_orz to traverse this edge.
The next lines each contain two positive integers and , representing the position of the -th anime character and the happiness value it can bring to zrz_orz.
The next lines each contain one positive integer , representing the dreaming time on the -th day.
Output Format
Output a total of lines. Each line contains one positive integer, representing the maximum happiness value zrz_orz can obtain on that day.
7 3 3
1 2 2
1 3 1
2 4 1
2 5 10
3 6 1
6 7 2
4 5
5 50
7 7
1
10
100
0
7
62
Hint

On the first day, he cannot go anywhere.
On the second day, taking the route , the maximum happiness value is .
On the third day, he can traverse all places once.
- Subtask 1 (20 pts): , , , .
- Subtask 2 (40 pts): , , , .
- Subtask 3 (40 pts): , , , , .
For all test points: , , , .
Note: The marked score is the score of this Subtask. Each Subtask must be completely correct to get the score. The time limit for Subtask 2 is 1.5 s.
Translated by ChatGPT 5