#abc214h. H - Collecting

H - Collecting

Score : 600600 points

问题描述

存在一个含有 NN 个顶点和 MM 条边的有向图。
顶点编号为 1,,N1, \dots, N,第 ii 条边(1iM1 \leq i \leq M)从顶点 AiA_i 指向顶点 BiB_i

最初,在顶点 ii 上有 XiX_i 件物品被某人丢失(1iN1 \leq i \leq N)。将会有 KK 个人来收集这些物品。

KK 个人将依次在图中移动。每个人将执行以下操作:

  • 从顶点 11 开始,然后可以任意多次遍历边。对于访问过的每个顶点(包括顶点 11),如果它们上面的物品尚未被收集,则收集所有物品。

找出能够收集到的最大物品总数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a directed graph with NN vertices and MM edges.
The vertices are numbered 1,,N1, \dots, N, and the ii-th edge (1iM)(1 \leq i \leq M) goes from Vertex AiA_i to Vertex BiB_i.

Initially, there are XiX_i items on Vertex ii (1iN)(1 \leq i \leq N) that someone has lost. KK people will collect these items.

The KK people will travel in the graph one by one. Each person will do the following.

  • Start on Vertex 11. Then, traverse an edge any finite number of times. For each vertex visited (including Vertex 11), collect all items on it if they have not been collected yet.

Find the maximum total number of items that can be collected.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1M2×1051 \leq M \leq 2 \times 10^5
  • 1K101 \leq K \leq 10
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • AiBiA_i \neq B_i
  • AiAjA_i \neq A_j or BiBjB_i \neq B_j, if iji \neq j.
  • 1Xi1091 \leq X_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM KK

A1A_1 B1B_1

\vdots

AMA_M BMB_M

X1X_1 \ldots XNX_N

Output

Print the answer.

Sample Input 1

5 5 2
1 2
2 3
3 2
1 4
1 5
1 4 5 2 8

Sample Output 1

18

The two people can collect 1818 items as follows.

  • The first person goes 12321 \rightarrow 2 \rightarrow 3 \rightarrow 2 and collects the items on Vertices 11, 22, and 33.
  • The second person goes 151 \rightarrow 5 and collects the items on Vertex 55.

It is impossible to collect 1919 or more items, so we should print 1818.

Sample Input 2

3 1 10
2 3
1 100 100

Sample Output 2

1

update @ 2024/3/10 09:32:22