luogu#P8281. 「MCOI-08」Fast Enumeration

    ID: 7120 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索洛谷原创O2优化剪枝洛谷月赛

「MCOI-08」Fast Enumeration

Problem Description

Technoblade abstracts Skyblock as a simple directed graph with nn nodes (n50n\le 50) and mm edges. He needs to find all Hamiltonian cycles in this graph, i.e., all permutations p1,p2,,pnp_1,p_2,\dots,p_n such that p1=1p_1=1 and p1p2pn1pnp1p_1\to p_2\to \dots\to p_{n-1}\to p_n\to p_1 is a valid path.

The testdata guarantees that the number of Hamiltonian cycles is non-zero and less than 10410^4.

The testdata is sampled randomly from all valid inputs.

Input Format

The first line contains two positive integers n,mn,m.

The next mm lines each contain two positive integers u,vu,v.

Output Format

Output several lines. Each line outputs nn positive integers, representing one Hamiltonian cycle. Output them in increasing lexicographical order.

3 3
1 2
2 3
3 1
1 2 3
4 6
1 3
1 4
2 1
2 3
3 4
4 2
1 3 4 2
5 8
1 2
2 3
3 4
4 1
2 5
4 5
5 1
5 3
1 2 3 4 5
1 2 5 3 4
5 10
1 2
1 3
2 3
2 4
3 4
3 5
4 1
4 5
5 1
5 2
1 2 3 4 5
1 3 5 2 4
6 15
1 3
1 4
1 5
2 1
2 3
2 4
3 1
3 4
4 2
4 6
5 2
5 3
6 1
6 2
6 3
1 5 2 3 4 6
1 5 2 4 6 3
1 5 3 4 6 2
6 15
1 3
1 5
2 1
2 4
3 1
3 2
3 4
3 5
3 6
4 6
5 1
5 4
5 6
6 3
6 5
1 3 2 4 6 5
1 5 4 6 3 2
6 16
1 3
1 6
2 3
2 4
2 6
3 1
3 6
4 2
4 3
4 5
4 6
5 2
5 6
6 1
6 3
6 5
1 6 5 2 4 3
6 21
1 2
1 5
1 6
2 1
2 3
2 4
2 5
3 1
3 2
3 4
3 6
4 1
4 2
4 6
5 1
5 2
5 4
5 6
6 2
6 3
6 4
1 2 5 4 6 3
1 2 5 6 3 4
1 5 2 3 6 4
1 5 2 4 6 3
1 5 4 6 2 3
1 5 4 6 3 2
1 5 6 2 3 4
1 5 6 3 2 4
1 5 6 3 4 2
1 5 6 4 2 3
1 6 3 2 5 4
1 6 3 4 2 5

Hint

Explanation for Sample 1

There is 11 Hamiltonian cycle:

  • 12311\to2\to3\to1.

Explanation for Sample 2

There is 11 Hamiltonian cycle:

  • 134211\to3\to4\to2\to1.

Explanation for Sample 3

There are 22 Hamiltonian cycles:

  • 1234511\to2\to3\to4\to5\to1;
  • 1253411\to2\to5\to3\to4\to1.

Explanation for Sample 4

There are 22 Hamiltonian cycles:

  • 1234511\to2\to3\to4\to5\to1;
  • 1352411\to3\to5\to2\to4\to1.

Explanation for Sample 5

There are 33 Hamiltonian cycles:

  • 15234611\to5\to2\to3\to4\to6\to1;
  • 15246311\to5\to2\to4\to6\to3\to1;
  • 15346211\to5\to3\to4\to6\to2\to1.

Explanation for Sample 6

There are 22 Hamiltonian cycles:

  • 13246511\to3\to2\to4\to6\to5\to1;
  • 15463211\to5\to4\to6\to3\to2\to1.

Explanation for Sample 7

There is 11 Hamiltonian cycle:

  • 16524311\to6\to5\to2\to4\to3\to1.

Explanation for Sample 8

There are 1212 Hamiltonian cycles:

  • 12546311\to2\to5\to4\to6\to3\to1;
  • 12563411\to2\to5\to6\to3\to4\to1;
  • 15236411\to5\to2\to3\to6\to4\to1;
  • 15246311\to5\to2\to4\to6\to3\to1;
  • 15462311\to5\to4\to6\to2\to3\to1;
  • 15463211\to5\to4\to6\to3\to2\to1;
  • 15623411\to5\to6\to2\to3\to4\to1;
  • 15632411\to5\to6\to3\to2\to4\to1;
  • 15634211\to5\to6\to3\to4\to2\to1;
  • 15642311\to5\to6\to4\to2\to3\to1;
  • 16325411\to6\to3\to2\to5\to4\to1;
  • 16342511\to6\to3\to4\to2\to5\to1.

Constraints and Notes

For fixed nn and PP, any graph with mm edges has weight $\left(\frac{1}{P}\right)^m\left(\frac{P-1}{P}\right)^{n^2-n-m}$.

  • Subtask 1 (1 pts): the samples.
  • Subtask 2 (16 pts): n=15n=15.
  • Subtask 3 (20 pts): n=30n=30.
  • Subtask 4 (26 pts): n=40n=40.
  • Subtask 5 (37 pts): n=50n=50.

Translated by ChatGPT 5