P27679 [洛谷] [GESP Sample Question Level 7] Longest Non-Decreasing Subsequence
普及+
题目描述

Problem Description

Xiao Yang has a directed acyclic graph with $n$ nodes and $m$ edges, where the nodes are numbered from $1$ to $n$.

For a node with number $i$, its weight is $w_i$. For a path in the graph, a sequence of node weights can be obtained based on the order of nodes traversed. Xiao Yang wants to know the maximum length of the longest non-decreasing subsequence among all possible sequences in the graph.

Note: Given a sequence $S$, its longest non-decreasing subsequence $S'$ is a subsequence of $S$ such that the entire subsequence $S'$ is monotonically non-decreasing and is the longest such subsequence in $S$. For example, given the sequence $S = [11, 12, 13, 9, 8, 17, 19]$, its longest non-decreasing subsequence is $S' = [11, 12, 13, 17, 19]$, with a length of $5$.

Input Format

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

The second line contains $n$ positive integers $A_1, A_2, \dots, A_n$, representing the weights of nodes $1$ to $n$.

The next $m$ lines each contain two positive integers $u_i, v_i$, indicating that the $i$-th edge connects node $u_i$ to node $v_i$ in the direction from $u_i$ to $v_i$.

Output Format

Output a single integer representing the answer.

Sample Input and Output

Sample Input #1

5 4
2 10 6 3 1
5 2
2 3
3 1
1 4

Sample Output #1

3

Sample Input #2

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

Sample Output #2

4

Sample Input #3

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

Sample Output #3

4

Notes

Data Size and Constraints

Subtask Score $n \le$ $A_i \le$ Special Constraints
$1$ $30$ $10^3$ $10$ The input graph is a chain
$2$ $30$ $10^5$ $2$ None
$3$ $40$ $10^5$ $10$ None

For all test data, it is guaranteed that $1 \leq n \leq 10^5$, $1 \leq m \leq 10^5$, and $1 \leq A_i \leq 10$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 4 2 10 6 3 1 5 2 2 3 3 1 1 4
样例输出
3