#P10287. [GESP样题 七级] 最长不下降子序列

[GESP样题 七级] 最长不下降子序列

Background

Related multiple-choice and true/false questions: https://ti.luogu.com.cn/problemset/1107.

Problem Description

Xiao Yang has a directed acyclic graph (DAG) with nn nodes and mm edges, where the nodes are numbered from 11 to nn.

For the node with index ii, its weight is AiA_i. For any path in the graph, following the order of nodes visited along the path gives a sequence of node weights. Xiao Yang wants to know, among all possible sequences in the graph, the maximum possible length of the longest non-decreasing subsequence.

Note: Given a sequence SS, its longest non-decreasing subsequence SS' is a subsequence of SS such that SS' is non-decreasing, and its length is as large as possible among all non-decreasing subsequences. For example, given S=[11,12,13,9,8,17,19]S = [11,12,13,9,8,17,19], its longest non-decreasing subsequence is S=[11,12,13,17,19]S' = [11,12,13,17,19], with length 55.

Input Format

The first line contains two positive integers n,mn, m, representing the number of nodes and the number of edges.

The second line contains nn positive integers A1,A2,AnA_1, A_2, \dots A_n, representing the node weights of nodes 11 to nn.

Then mm lines follow, each containing two positive integers ui,viu_i, v_i, indicating that the ii-th edge connects node uiu_i to node viv_i, directed from uiu_i to viv_i.

Output Format

Output one line containing one integer, representing the answer.

5 4
2 10 6 3 1
5 2
2 3
3 1
1 4
3
6 11
1 1 2 1 1 2
3 2
3 1
5 3
4 2
2 6
3 6
1 6
4 6
1 2
5 1
5 4
4
6 11
5 9 10 5 1 6
5 4
5 2
4 2
3 1
5 3
6 1
4 1
4 3
5 1
2 3
2 1
4

Hint

Constraints

Subtask Points nn \le AiA_i \le Special Constraint
11 3030 10310^3 1010 The input graph is a single chain.
22 10510^5 22 None.
33 4040 1010

For all testdata, it is guaranteed that 1n1051 \leq n \leq 10^5, 1m1051 \leq m \leq 10^5, and 1Ai101 \leq A_i \leq 10.

Translated by ChatGPT 5