#P3387. 【模板】缩点

【模板】缩点

Description

Given a directed graph with nn vertices and mm edges, each vertex has a weight. Find a path such that the sum of the weights of the vertices visited is maximized. You only need to output this sum.

You are allowed to traverse an edge or a vertex multiple times. However, if a vertex is visited repeatedly, its weight is counted only once.

Input Format

The first line contains two positive integers n,mn, m.

The second line contains nn integers, where the ii-th number aia_i is the weight of vertex ii.

Lines 3 through m+2m+2 each contain two integers u,vu, v, indicating a directed edge uvu \rightarrow v.

Output Format

Output a single line with the maximum sum of vertex weights.

2 2
1 1
1 2
2 1
2

Hint

Constraints: For 100%100\% of the testdata, 1n1041 \le n \le 10^4, 1m1051 \le m \le 10^5, 0ai1030 \le a_i \le 10^3.

Translated by ChatGPT 5