P14923 [GESP202512 Level 8] Cat and Mouse

Background

Corresponding multiple-choice and true/false questions:

Description

The manor where the cat and the mouse live can be regarded as a connected graph consisting of $n$ nodes and $m$ weighted undirected edges. The nodes are numbered $1,2,\ldots,n$, and node $i$ ($1\le i\le n$) has cheese worth $c_i$. Among the $m$ weighted undirected edges, the $i$-th ($1\le i\le m$) edge connects node $u_i$ and node $v_i$, and its weight $w_i$ is the time needed for the cat and the mouse to pass through this edge. The cat's nest is at node $a$, and the mouse's hole is at node $b$. For the mouse, a node $u$ is **safe** if and only if: - the mouse can plan a path starting from node $u$ and escaping to the mouse's hole such that, for every node $x$ on the path (including node $u$ and the mouse's hole), the shortest time for the cat to go from its nest to node $x$ is **strictly greater than** the time for the mouse to go from node $u$ **along this path** to node $x$. The mouse has no risk of being caught by the cat when taking the cheese at a safe node, but this is not guaranteed when taking the cheese at an unsafe node. To be completely safe, the mouse decides to take only the cheese placed at safe nodes. Please calculate the sum of the values of the cheese that the mouse can obtain.

Input Format

The first line contains two positive integers $n,m$, the number of nodes and the number of edges of the graph. The second line contains two positive integers $a,b$, the node number of the cat's nest and the node number of the mouse's hole. The third line contains $n$ positive integers $c_1,c_2,\ldots,c_n$, the value of the cheese at each node. In the next $m$ lines, the $i$-th line ($1\le i\le m$) contains three positive integers $u_i,v_i,w_i$, representing an edge connecting node $u_i$ and node $v_i$ with weight $w_i$.

Output Format

Output a single line with an integer, the sum of the values of the cheese that the mouse can obtain.

Explanation/Hint

For $40\%$ of the test data, it is guaranteed that $1\le n\le 500$ and $1\le m\le 500$. For all the test data, it is guaranteed that $1\le n\le 10^5$, $1\le m\le 10^5$, $1\le a,b\le n$ and $a\neq b$, $1\le u_i,v_i\le n$, and $1\le w_i\le 10^9$. Note: the original GESP problem omits the range of $c_i$, which can be treated as $1 \le c_i \le 10^9$. Translated by QwenWork