#P3323. [SDOI2015] 旅行计划

    ID: 2372 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2015山东深度优先搜索,DFS概率论,统计

[SDOI2015] 旅行计划

Description

In a country with NN cities, Alice wants to embark on a legendary journey. They wish to start from a city, each time moving to an adjacent city, visit exactly KK cities without repetition along the way, and finally arrive at another city to end the journey.

Note that the starting city and the ending city are also counted among the visited cities. That is, including the start and end, all visited cities must be distinct. Now, Alice wants to know which ordered city pairs (u,v)(u, v) can serve as a valid start and end for such a journey.

Input Format

Each test file contains multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case, the first line contains three integers NN, MM, and KK, denoting the number of cities, the number of adjacency relations between cities, and the number of cities that the trip should visit.

The next MM lines each contain two integers uu and vv, indicating that city uu and city vv are adjacent, i.e., you can travel from either city to the other.

N1000N\le 1000, M5000M\le 5000, 2K72\le K\le 7, and $T\times \left\lfloor \frac k 2 \right\rfloor^{\left\lfloor \frac k 2 \right\rfloor}\le 60$.

Output Format

For each test case, output NN lines, each containing NN characters. In the ii-th row, the jj-th character is either Y or N, indicating whether there exists a valid travel plan starting from city ii and ending at city jj.

1
5 6 4
1 2
2 3
3 5
1 4
4 5
2 5
NYYYY 
YNNYY 
YNNYN 
YYYNY 
YYNYN

Hint

2024-11-15: Added hack testdata.

Translated by ChatGPT 5