9159: Pumping

内存限制:128 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Prerequisite: Deterministic Finite Automaton, DFA
A deterministic finite automaton (DFA) MMM is a 5-tuple (Q,Σ,δ,q0,F)(Q,\Sigma,\delta,q_0,F)(Q,Σ,δ,q0,F), consisting of:

  • a finite set of states QQQ
  • a finite set of input symbols called the alphabet Σ\SigmaΣ
  • a transition function δ: Q×Σ→Q\delta:\ Q\times \Sigma \rightarrow Qδ: Q×ΣQ
  • a start state q0∈Qq_{0}\in Qq0Q
  • a set of accept states F⊆QF\subseteq QFQ (FFF is not empty)

Let s=c1c2⋯cns = c_1c_2\cdots c_ns=c1c2cn be a string over the alphabet Σ\SigmaΣ. The automaton MMM accepts\textbf{accepts}accepts the string sss if a sequence of states, r0, r1, ⋯, rnr_0,\ r_1,\ \cdots,\ r_nr0, r1, , rn, exists in QQQ with the following conditions:
  •  r0=q0r_0 = q_0r0=q0
  • ri+1=δ(ri,ci+1)r_{i+1} = \delta(r_i, c_{i+1})ri+1=δ(ri,ci+1), for i=0, ⋯, n−1i=0,\ \cdots,\ n-1i=0, , n1
  •  rn∈Fr_{n}\in FrnF.

In words, the first condition says that the machine starts in the start state q0q_0q0. The second condition says that given each character of string sss, the machine will transition from state to state according to the transition function δ\deltaδ. The last condition says that the machine accepts\textbf{accepts}accepts sss if the last input of sss causes the machine to halt in one of the accepting states. Otherwise, it is said that the automaton rejects\textbf{rejects}rejects the string - there is two cases where MMM rejects the string:
  • At some intermediate state rir_iri, there doesn't exists a transition of state rir_iri and character ci+1c_{i+1}ci+1, that is, (ri,ci+1)∉dom(δ)(r_i,c_{i+1})\notin dom(\delta)(ri,ci+1)/dom(δ).
  • The final state is not an accept state, that is, rn∉Fr_n\notin Frn/F.

The set of strings that MMM accepts is called the language recognized by MMM and this language is denoted by L(M)L(M)L(M).

Problem\textbf{Problem}Problem

You are given a deterministic finite automaton MMM. We say a string s∈L(M)s\in L(M)sL(M) can be \textit{pumped} if the string can be divided into three parts s=xyzs=xyzs=xyz satisfying:

  •  ∣y∣>0|y|>0y>0
  •  for each i≥0i\ge 0i0, xyiz∈L(M)xy^iz\in L(M)xyizL(M). Here yiy^iyi means repeating string yyy for iii times.


Please find a string in L(M)L(M)L(M) that can be pumped or report it is impossible.

输入格式


The first line contains three integers n, m, kn,~ m,~ kn, m, k (1≤n≤5×105, 0≤m≤106, 1≤k≤n1\le n\le 5\times 10^5,~ 0\le m\le 10^6,~1\le k\le n1n5×105, 0m106, 1kn), denoting the number of states, the number of transitions and the number of accept states in the DFA. We number the states in the DFA from 111 to nnn, and let the start state be state 111.
Then follows a line with kkk distinct integers a1, a2, ⋯, aka_1,\ a_2,\ \cdots,\ a_ka1, a2, , ak (1≤ai≤n1\le a_i\le n1ain), denoting the accept states.
Then follows mmm lines, and each line contains three integers u, v, cu,~v,~cu, v, c (1≤u, v≤n1\le u,\ v\le n1u, vn, and ccc is a lowercase character), denoting a transition δ(u,c)=v\delta(u, c)=vδ(u,c)=v in the DFA. It is guaranteed that there is at most one transition for each state uuu and each character ccc.
Note that the input data size can be large, so if you usestd::cin\texttt{std::cin}std::cin in C++\texttt{C++}C++, you may need to call std::ios::sync_with_stdio(false); cin.tie(nullptr);\texttt{std::ios::sync\_with\_stdio(false); cin.tie(nullptr);}std::ios::sync_with_stdio(false); cin.tie(nullptr); to disable stream synchronization.

输出格式


Print a string of length up to 3n3n3n that can be pumped. If there are multiple answers, print any. If there is no answer, print −1-11 instead.
It can be proved that if answer exists, then at least one answer has length 3n3n3n or less.

输入样例 复制

7 9 1
3
1 2 a
2 5 c
5 2 d
5 7 b
5 3 a
4 2 b
2 3 a
3 3 e
3 6 a

输出样例 复制

acdca

分类标签