#P3387. 【模板】缩点
【模板】缩点
Description
Given a directed graph with vertices and 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 .
The second line contains integers, where the -th number is the weight of vertex .
Lines 3 through each contain two integers , indicating a directed edge .
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 of the testdata, , , .
- 2024-11-1 Added hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号