Slay the Spire: Game Design
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
Special Judge, 64bit IO Format: %lld

题目描述

Bobo recently became obsessed with Slay the Spire, a deck-building roguelike game developed by Mega Crit. In Slay the Spire, players climb The Spire by ascending its floors and encountering various enemies, bosses, and events along the way. The map of Slay the Spire can be represented as a directed acyclic graph. Players can start at any source vertex, which are vertices with no incoming edges, and follow paths to reach any sink vertex, which are vertices with no outgoing edges and where bosses await. The map is designed in such a way where
  • each vertex has at least one outgoing edge or at least one incoming edge (no isolated vertices);
  • each vertex can reach at least one sink vertex, and can be reached from at least one source vertex through the edges.

After several games of Slay the Spire, Bobo becomes unsatisfied with simply playing, and now he wants to design the game by himself! The most important thing in game design is to control the difficulty of the game. So the first problem Bobo faces is to place the minimum number of elite enemies on some vertices (excluding source vertices and sink vertices) of the map so that no sneaky player can choose a path that avoids encountering at least k elite enemies. The formal definition of the problem is as follows:
You are given a directed acyclic graph G=(V, E) with no isolated vertices and a parameter k. Let S\subseteq V be the set of vertices with no incoming edges, and T\subseteq V be the set of vertices with no outgoing edges. You need to select a subset of vertices U\subseteq V\setminus (S\cup T) such that any path P from some s\in S to some t\in T satisfy |V(P)\cap U|\geq k. Here V(P) represents the set of vertices visited in P. If such a subset of vertices U exists, find any with the minimum size. Otherwise, report there is no such U.

输入描述:

The first line of input contains three integers n,m,k (2\leq n\leq 1000,1\leq m\leq 5000,1\leq k\leq 5), denoting the number of vertices, the number of edges and the parameter, respectively.

Then m lines follow, with each line containing two vertices u,v (1\leq u<v\leq n), denoting a directed edge in the graph. It is guaranteed that this graph contains no repeated edges; each vertex has at least one outgoing edge or at least one incoming edges; each vertex can reach at least one sink vertex, and can be reached from at least one source vertex through the edges..

输出描述:

If no valid subset of vertices exists, output -1 in a line. Otherwise, output a nonnegative integer \ell in a line, denoting the size of the subset of vertices you choose. Then output \ell distinct numbers v_1,v_2,\dots,v_{\ell} (1\leq v_i\leq n) in a line, denoting the subset of vertices you choose. If there are multiple valid subset of vertices with the smallest size, outputting any of them will be considered correct.
示例1

输入

复制
3 2 1
1 2
2 3

输出

复制
1
2
示例2

输入

复制
3 2 2
1 2
2 3

输出

复制
-1
示例3

输入

复制
8 8 2
1 3
2 3
3 4
3 5
4 6
5 6
6 7
6 8

输出

复制
2
3 6
示例4

输入

复制
6 14 1
1 2
1 3
2 3
1 4
2 4
3 4
1 5
2 5
3 5
4 5
2 6
3 6
4 6
5 6

输出

复制
4
2 3 4 5
示例5

输入

复制
15 14 2
1 2
1 3
2 4
2 5
3 6
3 7
4 8
4 9
5 10
5 11
6 12
6 13
7 14
7 15

输出

复制
6
2 3 4 5 6 7

备注:

Here, we provide graphical illustrations for the third sample test to help with understanding. The graph given in the input is shown as follows.

In this graph, the set of source vertices is \{1,2\}, and the set of sink vertices is \{7,8\}. We can place elite enemies at the remaining set of vertices, namely \{3,4,5,6\}. The only optimal solution is to place elites on vertex 3 and vertex 6. In the following picture, we mark source vertices by flags, sink vertices by skeletons (representing bosses in-game), and elite enemies by swords.

The distinct types of vertices (left) and the only optimal solution (right)

For example, choosing vertices \{3,4,5\} is also valid. However, this solution is not optimal as it has a size of 3. Choosing vertices \{3,4\} is not valid, as then there would exist a path from a source vertex to a sink vertex, encountering only one elite enemy. These two examples are shown in the following picture.


An solution that is not optimal (left) and a non-solution (right)