#abc335e. E - Non-Decreasing Colorful Path
E - Non-Decreasing Colorful Path
Score : points
问题描述
存在一个含有 个顶点和 条边的连通无向图,其中第 条边在顶点 和顶点 之间双向连接。
每个顶点上都写有一个整数,顶点 上写有整数 。
对于从顶点 到顶点 的一条简单路径(即不经过同一顶点多次的路径),其得分确定方式如下:
- 设 是沿该路径按访问顺序列出的顶点上的整数序列。
- 如果 不是非递减序列,则该路径的得分为 。
- 否则,得分为 中不同整数的数量。
在所有简单路径中找到从顶点 到顶点 的最高得分路径,并输出该得分。
什么是非递减序列?长度为 的序列 被称为非递减序列,当且仅当对于所有满足 的整数,都有 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There is a connected undirected graph with vertices and edges, where the -th edge connects vertex and vertex bidirectionally.
Each vertex has an integer written on it, with integer written on vertex .
For a simple path from vertex to vertex (a path that does not pass through the same vertex multiple times), the score is determined as follows:
- Let be the sequence of integers written on the vertices along the path, listed in the order they are visited.
- If is not non-decreasing, the score of that path is .
- Otherwise, the score is the number of distinct integers in .
Find the path from vertex to vertex with the highest score among all simple paths and print that score.
What does it mean for to be non-decreasing? A sequence of length is said to be non-decreasing if and only if for all integers .
Constraints
- All input values are integers.
- The graph is connected.
- if .
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
5 6
10 20 30 40 50
1 2
1 3
2 5
3 4
3 5
4 5
Sample Output 1
4
The path has for a score of , which is the maximum.
Sample Input 2
4 5
1 10 11 4
1 2
1 3
2 3
2 4
3 4
Sample Output 2
0
There is no simple path from vertex to vertex such that is non-decreasing. In this case, the maximum score is .
Sample Input 3
10 12
1 2 3 3 4 4 4 6 5 7
1 3
2 9
3 4
5 6
1 2
8 9
4 5
8 10
7 10
4 6
2 8
6 7
Sample Output 3
5
update @ 2024/3/10 01:24:12