#P6516. [QkOI#R1] Quark and Graph
[QkOI#R1] Quark and Graph
Description
You are given a labeled, simple, undirected, connected graph where all edge weights are . It has vertices and edges. You are also given the shortest path distances from vertex to every vertex. Find how many different graphs (forms) satisfy these conditions.
In particular, we define the shortest distance from vertex to vertex as .
Two graphs are considered different if and only if there exists at least one edge that appears in one graph but does not appear in the other.
Since little_sun is extremely strong, the testdata guarantees that there is at least one graph that satisfies the conditions.
Output the answer modulo .
Input Format
The first line contains two positive integers , where is the number of vertices and is the number of edges.
The second line contains non-negative integers , representing the shortest path distance from vertex to each vertex.
Output Format
Output one line with one integer, the answer.
4 3
0 1 1 2
2
5 5
0 1 1 2 2
12
8 12
0 2 2 2 2 1 1 1
128601
Hint
Sample Explanation
For the first sample, there are two forms: and .
For the second sample, I came up with a wonderful explanation, but unfortunately this blank space is too small to write it down.
Constraints
This problem uses bundled tests.
- Subtask 1 (10 pts): , , time limit 1s.
- Subtask 2 (20 pts): , , time limit 1s.
- Subtask 3 (20 pts): , , time limit 1s.
- Subtask 4 (50 pts): no special constraints, time limit 3s.
For of the data: , . Let . It is also required that .
This problem forces O2 optimization to be enabled.
Translated by ChatGPT 5
京公网安备 11011102002149号