#abc212e. E - Safety Journey
E - Safety Journey
Score : points
问题描述
在AtCoder共和国中,有个城市,分别称为城市1、城市2、、城市。最初,每一对不同的城市之间都有一条双向道路,但由于时间推移,其中有条道路已经无法使用。具体来说,对于每个,连接城市和城市的道路已变得不可用。
Takahashi将进行一场为期天的旅行,起点和终点都在城市1。形式上来说,一场起点和终点均为城市1的天旅行是一个包含个城市的序列,满足,并且对于每个,和不同,并且仍然存在一条可以使用的道路连接城市和城市。
请计算并输出以城市1为起点和终点的不同天旅行的数量,结果对取模。这里,两个天旅行和被认为是不同的,当且仅当存在某个使得。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
The Republic of AtCoder has cities, called City , City , , City . Initially, there was a bidirectional road between every pair of different cities, but of these roads have become unusable due to deterioration over time. More specifically, for each , the road connecting City and City has become unusable.
Takahashi will go for a -day trip that starts and ends in City . Formally speaking, a -day trip that starts and ends in City is a sequence of cities such that holds and for each , and are different and there is still a usable road connecting City and City .
Print the number of different -day trips that start and end in City , modulo . Here, two -day trips and are said to be different when there exists an such that .
Constraints
- $0 \leq M \leq \min\left( \frac{N(N-1)}{2},5000 \right)$
- All pairs are pairwise distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3 1 4
2 3
Sample Output 1
4
There are four different trips as follows.
- ()
- ()
- ()
- ()
No other trip is valid, so we should print .
Sample Input 2
3 3 3
1 2
1 3
2 3
Sample Output 2
0
No road remains usable, so there is no valid trip.
Sample Input 3
5 3 100
1 2
4 5
2 3
Sample Output 3
428417047
update @ 2024/3/10 09:27:49