#P13856. [CERC 2023] Labelled Paths

    ID: 15656 远端评测题 15000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023Special Judge哈希 hashing后缀数组 SAICPCCERC

[CERC 2023] Labelled Paths

题目描述

We are given a directed acyclic graph with nn vertices and mm 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 ss to a destination vertex tt is the path (from ss to tt) whose label is lexicographically smallest (i.e. the earliest in lexicographical order) amongst all the paths from ss to tt. Write a program that, for a given ss, outputs the smallest paths from ss to tt for all vertices tt of the graph.

输入格式

The first line contains four space-separated integers: nn (the number of vertices), mm (the number of edges), dd (the length of the string AA, on which see below) and ss (the number of the start vertex). The vertices are numbered by integers from 11 to nn.

The second line contains a string AA, which is exactly dd characters long; all these characters are lowercase letters of the English alphabet. All the edge labels in our graph are substrings of the string AA.

The remaining mm lines describe the edges of the graph. The ii-th of these lines describes the ii-th edge and contains four space-separated integers: uiu_i (the start vertex of this edge), viv_i (the end vertex of this edge), pip_i and i\ell_i. The last two of these integers indicate that the label of this edge is the substring of AA that begins with the pip_i-th character of AA and is i\ell_i characters long. For this purpose we consider the characters of AA to be indexed by integers from 11 to dd.

输出格式

Output nn lines, where the tt-th line (for t=1,,nt = 1, \dots, n) describes the smallest path from ss to tt. If there is no path from ss to tt, the line should contain only the integer 00 and nothing else. Otherwise the line should start with the number of vertices on the path (including vertices ss and tt), 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 313 \rightarrow 1 has the label ab; the edge 141 \rightarrow 4 has the label a; the smallest path from 33 to 44 is 3143 \rightarrow 1 \rightarrow 4, whose label is aba.

Input limits

  • 1sn6001 \leq s \leq n \leq 600
  • 1m20001 \leq m \leq 2000
  • 1d1061 \leq d \leq 10^6
  • 1uin1 \leq u_i \leq n, 1vin1 \leq v_i \leq n, uiviu_i \neq v_i (for all i=1,,mi = 1, \dots, m)
  • 1pi1 \leq p_i, 0i0 \leq \ell_i, pi+i1dp_i + \ell_i - 1 \leq d (for all i=1,,mi = 1, \dots, m)
  • The graph is acyclic and has no parallel edges (i.e. from iji \neq j it follows that uiuju_i \neq u_j and/or vivjv_i \neq v_j).