#P1261. [CERC2002] 服务器储存信息问题
[CERC2002] 服务器储存信息问题
Description
The Kingdom of Byteland is preparing to build a large network among its servers and provide various services.
The network consists of servers, connected by bidirectional links. There is at most one direct link between any pair of servers. Each server is directly connected to at most servers. Furthermore, there is a path between any two servers.
Each transmission link has a fixed length. Let denote the length of the shortest path between servers and , and for any we have .
Some servers provide more services than others and are therefore more important. We use to denote the importance of server . A higher means a more important server.
Each server stores information about nearby servers. Of course, not all servers’ information is stored—only the interesting ones. Server is interested in server if there does not exist a server such that and .
For example, all servers with the highest are interesting to every other server. If has the highest , then since , is interested only in servers with the highest .
We define as the set of servers that server is interested in. We want to compute the total amount of information stored by all servers, i.e., the sum of over all servers. Byteland does not want to store a large amount of data, so the total amount of stored data (the sum of ) will not exceed .
Your task is to write a program that reads the network layout of Byteland and computes the total amount of information stored by all servers.
Input Format
The first line contains two integers and . Here is the number of servers and is the number of transmission links.
The next lines each contain one integer. The integer on the -th line is , the of server .
The next lines each describe a transmission link with three integers . Here and are the indices of the two servers connected by the link, and is the length of the link.
Output Format
Output a single integer: the total amount of data stored by all servers, i.e., the sum of .
4 3
2
3
1
1
1 4 30
2 3 20
3 4 20
9
Hint
Output explanation:
$B(1)=\{1,2\},B(2)=\{2\},B(3)=\{2,3\},B(4)=\{1,2,3,4\}$.
Constraints:
.
Translated by ChatGPT 5
京公网安备 11011102002149号