#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 nodes and edges, where the nodes are numbered from to .
For the node with index , its weight is . 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 , its longest non-decreasing subsequence is a subsequence of such that is non-decreasing, and its length is as large as possible among all non-decreasing subsequences. For example, given , its longest non-decreasing subsequence is , with length .
Input Format
The first line contains two positive integers , representing the number of nodes and the number of edges.
The second line contains positive integers , representing the node weights of nodes to .
Then lines follow, each containing two positive integers , indicating that the -th edge connects node to node , directed from to .
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 | Special Constraint | ||
|---|---|---|---|---|
| The input graph is a single chain. | ||||
| None. | ||||
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5