Logo
(追記) (追記ここまで)

19024번 - Hamilton Path 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 512 MB24000.000%

문제

You are given a directed graph with $n$ vertices and $m$ edges. The vertices are labeled from 1ドル$ to $n$. You need to find all the permutations of vertices $p_1, p_2, \ldots, p_n$ satisfying the following constraint:

  • For all 1ドル \leq i < j \leq n,ドル an edge $(p_i, p_j)$ exists if and only if $j = i + 1$.

We define the value of a permutation $p_1, p_2, \ldots, p_n$ as $$\left(\sum_{i = 1}^n p_i \cdot 10^{n - i}\right) \bmod (10^9 + 7)\text{.}$$

Output the number of such permutations modulo 10ドル^9 + 7$. If the number of such permutations is not greater than $n,ドル you also need to consider them all in lexicographical order, and output their values in this order.

입력

The first line contains an integer $T$ ($T \leq 10^5$) indicating the number of test cases.

For each test case, the first line contains two integers $n$ and $m$ ($n \geq 1,ドル $m \geq 0,ドル 1ドル \leq \sum n \leq 5 \cdot 10^5,ドル 1ドル \leq \sum m \leq 10^6$).

Each of the following $m$ lines contains two integers $u$ and $v$ (1ドル \leq u, v \leq n,ドル $u \neq v$) indicating that there is a directed edge from $u$ to $v$ in the graph. Note that the graph can contain parallel edges.

출력

For each test case, output the number of the permutations modulo 10ドル^9 + 7$ in the first line. If the number of permutations is not greater than $n,ドル print another line with space-separated values of all the permutations, considered in lexicographical order. You \textbf{don't need to} output an empty line if the number is greater than $n$ or there is no solution.

제한

예제 입력 1

1
5 6
3 4
2 5
5 3
1 3
4 2
5 1

예제 출력 1

2
13425 34251

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 8: Yuhao Du Contest 5, Grand Prix of Zhejiang H번

Contest > Open Cup > 2018/2019 Season > Stage 1: Grand Prix of Zheijang H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /