#P4742. Kite Light Maximization
Kite Light Maximization
Kite Light Maximization
After a day of activities, all the students pause to admire the kites lit under the night sky. Curtis Nishikino wants to experience the scene from a closer perspective, so she runs onto one of the kites (which is rather astonishing for a girl!). Each kite has a brightness value \(k_i\). Due to the wind, some kites become entangled; yet this only serves to combine their lights into a brighter source.
Additionally, Curtis knows some one‐way relationships between the kites. Each given pair \((a, b)\) indicates that she can run from kite \(a\) to kite \(b\) (but not back).
Your task is to help her find a path that allows her to experience the maximum possible light. Note that she collects the brightness of a kite only the first time she visits it (although she may land on the same kite multiple times). In the end, you must output two numbers:
- The total brightness collected along the optimal path.
- The maximum brightness among any single kite visited on that path.
If there are multiple paths that yield the same total brightness, choose the one whose visited kites contain the largest individual brightness.
Note: You are free to start from any kite and move along the given one‐way relationships. It is guaranteed that the input relationships form a directed acyclic graph (DAG).
inputFormat
The input begins with a line containing two integers \(n\) and \(m\) \((1 \leq n \leq 10^5,\ 0 \leq m \leq 10^5)\) which denote the number of kites and the number of one‐way relationships, respectively.
The second line contains \(n\) integers \(k_1, k_2, \ldots, k_n\) \((1 \leq k_i \leq 10^9)\), where \(k_i\) is the brightness of the \(i\)-th kite.
The following \(m\) lines each contain two integers \(a\) and \(b\) \((1 \leq a, b \leq n)\) representing a one‐way move from kite \(a\) to kite \(b\). It is guaranteed that once you move from a to b, you cannot return directly from b to a, and the overall graph is a DAG.
outputFormat
Output two integers separated by a space. The first integer is the maximum total brightness that Curtis can experience by following an optimal path. The second integer is the maximum brightness among any single kite on that chosen path. If multiple paths yield the same total brightness, the one with the highest individual kite brightness should be chosen.
sample
3 2
1 2 3
1 2
2 3
6 3