#C6868. Longest Increasing Paths

    ID: 50675 Type: Default 1000ms 256MiB

Longest Increasing Paths

Longest Increasing Paths

You are given an undirected graph with N vertices and M edges. Each vertex is assigned a weight. A path in the graph is called weight-increasing if the sequence of weights of the vertices in the path is strictly increasing. Your task is to compute two values:

  • The length of the longest weight-increasing path.
  • The number of such longest paths modulo \(998244353\).

Note: A path may consist of a single vertex. The graph is undirected, and an edge between vertices u and v can be traversed in both directions, but the path can only continue if the weight of the next vertex is strictly greater than the current vertex's weight.

Example:

Input:
6 7
1 2 5 4 3 6
1 2
1 3
2 5
3 4
3 5
4 6
5 6

Output: 4 2

</p>

inputFormat

The first line contains two integers N and M, representing the number of vertices and edges respectively.

The second line contains N integers, where the ith integer represents the weight of vertex i.

The following M lines each contain two integers u and v, indicating that there is an undirected edge connecting vertices u and v.

outputFormat

Output two integers separated by a space. The first integer is the length of the longest weight-increasing path and the second integer is the number of such paths modulo \(998244353\).

## sample
6 7
1 2 5 4 3 6
1 2
1 3
2 5
3 4
3 5
4 6
5 6
4 2