#P13856. [CERC 2023] Labelled Paths
[CERC 2023] Labelled Paths
题目描述
We are given a directed acyclic graph with vertices and edges. Each edge has a label (a string of lowercase letters; possibly even an empty string). We can now extend the concept of labels from edges to paths by defining the label of a path as the concatenation of the labels of the edges that constitute this path (in the same order in which they appear in the path). The smallest path from a start vertex to a destination vertex is the path (from to ) whose label is lexicographically smallest (i.e. the earliest in lexicographical order) amongst all the paths from to . Write a program that, for a given , outputs the smallest paths from to for all vertices of the graph.
输入格式
The first line contains four space-separated integers: (the number of vertices), (the number of edges), (the length of the string , on which see below) and (the number of the start vertex). The vertices are numbered by integers from to .
The second line contains a string , which is exactly characters long; all these characters are lowercase letters of the English alphabet. All the edge labels in our graph are substrings of the string .
The remaining lines describe the edges of the graph. The -th of these lines describes the -th edge and contains four space-separated integers: (the start vertex of this edge), (the end vertex of this edge), and . The last two of these integers indicate that the label of this edge is the substring of that begins with the -th character of and is characters long. For this purpose we consider the characters of to be indexed by integers from to .
输出格式
Output lines, where the -th line (for ) describes the smallest path from to . If there is no path from to , the line should contain only the integer and nothing else. Otherwise the line should start with the number of vertices on the path (including vertices and ), followed by the list of those vertices, separated by spaces. If there are several possible solutions, you may output any of them.
5 7 6 3
abcbca
3 2 1 1
2 1 5 1
2 5 4 2
3 1 1 2
3 4 3 2
1 4 6 1
5 4 5 2
2 3 1
2 3 2
1 3
3 3 1 4
3 3 2 5
提示
Comment
In this example, the edge has the label ab; the edge has the label a; the smallest path from to is , whose label is aba.
Input limits
- , , (for all )
- , , (for all )
- The graph is acyclic and has no parallel edges (i.e. from it follows that and/or ).