#P17453. AC 自动机 / AC Automaton
AC 自动机 / AC Automaton
Problem Description
Given a deterministic finite automaton (DFA) with state set , start state , accepting state set of size , and alphabet . Compute the lexicographically smallest string that can be accepted by the automaton and has length at least . Since the answer may be very long, if the length of the answer exceeds , you only need to output the last characters of the answer. If no string satisfying the above requirements exists, output WA.
A string is accepted by the automaton if and only if there exists a walk that starts from the start state and ends at an accepting state, such that the letters on the transition edges traversed form exactly the string. The walk may visit repeated states and repeated edges.
Input Format
This problem contains multiple test cases.
The first line contains an integer (), indicating the number of test cases.
For each test case:
- The first line contains three integers separated by spaces: the number of states (), the number of accepting states (), and the minimum length ().
- The second line contains integers separated by spaces, indicating the accepting state set. It is guaranteed that these numbers are all in $[2,n]` and are distinct.
- The next lines each contain integers separated by spaces. In line , the two integers represent the state reached from state by transitions labeled
AandC, respectively.
It is guaranteed that .
Output Format
Output lines. Each line outputs one string, where the -th line is the answer for the -th test case.
2
5 1 6
4
2 5
5 3
4 2
5 5
5 5
3 1 2
2
2 3
3 3
3 3
CCCCA
WA
Hint
In the first sample test case, the language recognized by the DFA is $\{\texttt{A}\texttt{C}^{2t+1}\texttt{A}\mid t\ge 0\}$.
Translated by ChatGPT 5