#abc213h. H - Stroll
H - Stroll
Score : points
问题描述
高桥决定在自家周围闲逛。
在他的漫步过程中,他将在被称为 Point 1、Point 2、...、Point N 的 个点之间漫游,其中 Point 1 是他的家。
有 对由道路连接的点对;设 表示第 对这样的点对。在 Point 和 Point 之间有长度为 ()千米的道路,共有 条。
高桥想知道从他家出发并返回到他家的 千米路线的数量。这里,一个 千米路线定义如下:
- 一个交替的点和道路序列 ,满足 连接 和 ,且所有 的总长度为 千米。
请帮助高桥计算满足条件的路线数量,并将结果对 取模。当两条路线作为序列时不同,则认为它们是不同的路线。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has decided to wander around his house.
During his walk, he will roam between points called Point , Point , , Point , where Point is his house.
There are pairs of points connected by roads; let be the -th of these pairs. There are roads with a length of kilometers connecting Point and Point .
Takahashi wants to know the number of kilometers courses that begin and end at his house. Here, a kilometers course is defined as follows.
- An alternating sequence with points and roads such that connects and , and the total length of is kilometers.
Help Takahashi by finding the number of such courses modulo . Two courses are considered different when they are different as sequences.
Constraints
- $1 \leq M \leq \min \left(10, \frac{N(N-1)}{2} \right)$
- if .
Input
Input is given from Standard Input in the following format:
Output
Print the number of desirable courses, modulo .
Sample Input 1
3 2 2
1 2
1 0
1 3
2 0
Sample Output 1
5
Around his house, there are:
- one -kilometer road connecting Point and Point , and
- two -kilometer roads connecting Point and Point .
We have the following five desirable courses:
- course that goes Point Point Point , and
- courses that goes Point Point Point .
Sample Input 2
3 3 4
1 2
3 0 0 0
1 3
0 1 0 0
2 3
2 0 0 0
Sample Output 2
130
Around his house, there are:
- three -kilometer roads connecting Point and Point ,
- one -kilometer road connecting Point and Point , and
- two -kilometer roads connecting Point and Point .
The desirable courses can be classified into the following categories, according to the points visited:
- Point Point Point Point Point ,
- Point Point Point Point ,
- Point Point Point Point Point ,
- Point Point Point , and
- Point Point Point Point .
We have , , , , and course(s) of these categories, respectively.
Sample Input 3
2 1 5
1 2
31415 92653 58979 32384 62643
Sample Output 3
844557977
update @ 2024/3/10 09:30:44