Hide

Problem F
Hammer to Fall

Boboland is a beautiful country with $n$ cities and $m$ two-way roads, ruled by King Bobo. A two-way road $(u,v,w)$ connects city $u$ and city $v$ with distance $w$. It is guaranteed that for each city $v$ in Boboland, at least one road has $v$ as an endpoint.

There were $a_ i$ residents in the $i$-th city, living a happy and peaceful life until the day came when hammers began to fall! Specifically, every day hammers will start to fall on exactly one city of Boboland putting all citizens of that city in danger.

As the king of Boboland, Bobo needs to deal with this situation. Unfortunately, he doesn’t know why this disaster would happen and he can’t figure out a way to prevent even one hammer from falling. Despite this, he figured out the following “dynamic zero-casualty policy”: it is OK as long for a hammer to fall on a city if all residents in that city have already been transferred to some other city so nobody is ever in danger. The cost of transferring a single resident across a road $(u,v,w)$ is, of course, $w$.

After talking with the prophet in Boboland, Bobo has gained learned following information: in the upcoming $q$ days, hammers will fall on cities $b_1,b_2,...,b_ q$ in that order. At any time, Bobo can arrange to transfer any single resident at some city $u$ to some adjacent city $v$ with cost $w$ if a road $(u,v,w)$ exists. Multiple residents can be transferred simultaneously. Also, any resident can be transferred multiple times.

Bobo wants to ensure no resident is ever in danger during these $q$ days using the minimum total movement cost. But, as always, a king never does the counting by himself, so you have to calculate the minimum cost to achieve the goal.

Since the answer might be large, you should output the answer modulo $998\, 244\, 353$. Note that your minimization target is still the total movement cost before reducing it by the modulus, not after.

Input

The first line contains three integers $n,m,q$ $(2 \leq n \leq 10^5, 1\leq m,q\leq 10^5)$ denoting the number of cities in Boboland, the number of roads in Boboland, and the length of information from the prophet, respectively.

The second line contains $n$ integers $a_1,a_2,...,a_ n$ $(1\leq a_ i\leq 10^9)$, denoting the number of residents initially located in each city.

Then $m$ lines follow, each line containing $3$ integers $u,v,w$ $(1\leq u,v\leq n,u\neq v,1\leq w\leq 10^9)$, denoting a two-way road $(u,v,w)$ in Boboland. It is guaranteed that each city in Boboland has at least one road connects to it.

The next line contains $q$ integers $b_1,b_2,...,b_ q$ $(1\leq b_ i\leq n)$, denoting the city on which the hammer will fall in the upcoming $q$ days, in order.

Output

Output an integer in one line, denoting the minimum cost to achieve Bobo’s goal, modulo $998\, 244\, 353$.

Sample Input 1 Sample Output 1
3 2 2
1 1 1
2 3 10
1 2 1
3 2
12
Sample Input 2 Sample Output 2
2 1 10
5000 5000
1 2 10000
1 2 2 1 2 2 1 1 1 2
550000000

Please log in to submit a solution to this problem

Log in